Commit 71f8956e authored by Yury Shvedov's avatar Yury Shvedov
Browse files

freecad: add tests for modules

Change-Id: Ia5b5fb54120555b75fbeba6493f57f07d05dc2fc
parent d3c8c86a
Loading
Loading
Loading
Loading
+1 −18
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
, eigen
, fetchFromGitHub
, fmt
, freecad
, gfortran
, gts
, hdf5
@@ -23,7 +22,6 @@
, opencascade-occt_7_6
, pkg-config
, python311Packages
, runCommand  # for passthru.tests
, spaceNavSupport ? stdenv.hostPlatform.isLinux
, stdenv
, swig
@@ -177,22 +175,7 @@ freecad-utils.makeCustomizable (stdenv.mkDerivation (finalAttrs: {
    ln -s $out/bin/FreeCADCmd $out/bin/freecadcmd
  '';

  passthru.tests = {
    # Check that things such as argument parsing still work correctly with
    # the above PYTHONPATH patch. Previously the patch used above changed
    # the `PyConfig_InitIsolatedConfig` to `PyConfig_InitPythonConfig`,
    # which caused the built-in interpreter to attempt (and fail) to doubly
    # parse argv. This should catch if that ever regresses and also ensures
    # that PYTHONPATH is still respected enough for the FreeCAD console to
    # successfully run and check that it was included in `sys.path`.
    python-path =
      runCommand "freecad-test-console"
        {
          nativeBuildInputs = [ freecad ];
        } ''
        HOME="$(mktemp -d)" PYTHONPATH="$(pwd)/test" FreeCADCmd --log-file $out -c "if not '$(pwd)/test' in sys.path: sys.exit(1)" </dev/null
      '';
  };
  passthru.tests = callPackage ./tests {};

  meta = {
    homepage = "https://www.freecad.org";
+7 −0
Original line number Diff line number Diff line
{
  callPackage,
}:
{
  python-path = callPackage ./python-path.nix { };
  modules = callPackage ./modules.nix { };
}
+42 −0
Original line number Diff line number Diff line
{
  freecad,
  runCommand,
  writeTextFile,
}:
let
  mkModule =
    n:
    writeTextFile {
      name = "module-${n}";
      destination = "/Init.py";
      text = ''
        import sys
        import os

        out = os.environ['out']
        f = open(out + "/module-${n}.touch", "w")
        f.write("module-${n}");
        f.close()
      '';
    };
  module-1 = mkModule "1";
  module-2 = mkModule "2";
  freecad-customized = freecad.customize {
    modules = [
      module-1
      module-2
    ];
  };
in
runCommand "freecad-test-modules"
  {
    nativeBuildInputs = [ freecad-customized ];
  }
  ''
    mkdir $out
    HOME="$(mktemp -d)" FreeCADCmd --log-file $out/freecad.log -c "sys.exit(0)" </dev/null
    test -f $out/module-1.touch
    test -f $out/module-2.touch
    grep -q 'Initializing ${module-1}... done' $out/freecad.log
    grep -q 'Initializing ${module-2}... done' $out/freecad.log
  ''
+18 −0
Original line number Diff line number Diff line
{
  freecad,
  runCommand,
}:
# Check that things such as argument parsing still work correctly with
# the above PYTHONPATH patch. Previously the patch used above changed
# the `PyConfig_InitIsolatedConfig` to `PyConfig_InitPythonConfig`,
# which caused the built-in interpreter to attempt (and fail) to doubly
# parse argv. This should catch if that ever regresses and also ensures
# that PYTHONPATH is still respected enough for the FreeCAD console to
# successfully run and check that it was included in `sys.path`.
runCommand "freecad-test-console"
  {
    nativeBuildInputs = [ freecad ];
  }
  ''
    HOME="$(mktemp -d)" PYTHONPATH="$(pwd)/test" FreeCADCmd --log-file $out -c "if not '$(pwd)/test' in sys.path: sys.exit(1)" </dev/null
  ''