Skip to content
Snippets Groups Projects
tests.nix 2.01 KiB
Newer Older
  • Learn to ignore specific revisions
  • let
      sources = import nix/sources.nix;
    in
    
    Tom Prince's avatar
    Tom Prince committed
    { pkgs ? import sources.release2015 {}
    , pypiData ? sources.pypi-deps-db
    , mach-nix ? import sources.mach-nix { inherit pkgs pypiData; }
    
    Tom Prince's avatar
    Tom Prince committed
    , tahoe-lafs-source ? "tahoe-lafs"
    , tahoe-lafs-repo ? sources.${tahoe-lafs-source}
    , privatestorage ? import ./. {
        inherit pkgs pypiData mach-nix;
        inherit tahoe-lafs-repo;
      }
    
    Tom Prince's avatar
    Tom Prince committed
    , hypothesisProfile ? null
    , collectCoverage ? false
    , testSuite ? null
    , trialArgs ? null
    ,
    
    Tom Prince's avatar
    Tom Prince committed
      let
    
    Tom Prince's avatar
    Tom Prince committed
        inherit (pkgs) lib;
        inherit (privatestorage) zkapauthorizer;
    
    Tom Prince's avatar
    Tom Prince committed
        hypothesisProfile' = if hypothesisProfile == null then "default" else hypothesisProfile;
        defaultTrialArgs = [ "--rterrors" ] ++ (lib.optional (! collectCoverage) "--jobs=$NIX_BUILD_CORES");
        trialArgs' = if trialArgs == null then defaultTrialArgs else trialArgs;
        extraTrialArgs = builtins.concatStringsSep " " trialArgs';
        testSuite' = if testSuite == null then "_zkapauthorizer" else testSuite;
    
    Tom Prince's avatar
    Tom Prince committed
        python = mach-nix.mkPython {
          inherit (zkapauthorizer.meta.mach-nix) python providers;
          requirements =
    
    Tom Prince's avatar
    Tom Prince committed
            builtins.readFile ./requirements/test.in;
    
    Tom Prince's avatar
    Tom Prince committed
          packagesExtra = [ zkapauthorizer ];
          _.hypothesis.postUnpack = "";
        };
    
    
        lint-python = mach-nix.mkPython {
          python = "python39";
          requirements = ''
            isort
            black
          '';
        };
    
    Tom Prince's avatar
    Tom Prince committed
      in
    
    Tom Prince's avatar
    Tom Prince committed
        pkgs.runCommand "zkapauthorizer-tests" {
          passthru = {
            inherit python;
          };
        } ''
    
    Tom Prince's avatar
    Tom Prince committed
          mkdir -p $out
    
    
    Tom Prince's avatar
    Tom Prince committed
          pushd ${zkapauthorizer.src}
          ${python}/bin/pyflakes
    
          ${lint-python}/bin/black --check src
          ${lint-python}/bin/isort --check src
    
    Tom Prince's avatar
    Tom Prince committed
          popd
    
    Tom Prince's avatar
    Tom Prince committed
          ZKAPAUTHORIZER_HYPOTHESIS_PROFILE=${hypothesisProfile'} ${python}/bin/python -m ${if collectCoverage
    
    Tom Prince's avatar
    Tom Prince committed
            then "coverage run --debug=config --rcfile=${zkapauthorizer.src}/.coveragerc --module"
            else ""
          } twisted.trial ${extraTrialArgs} ${testSuite'}
    
    Tom Prince's avatar
    Tom Prince committed
    
    
    Tom Prince's avatar
    Tom Prince committed
          ${lib.optionalString collectCoverage
    
    Tom Prince's avatar
    Tom Prince committed
            ''
              mkdir -p "$out/coverage"
              cp -v .coverage.* "$out/coverage"
            ''
          }
    
    Tom Prince's avatar
    Tom Prince committed
        ''