From 1be924529d24c86d8b2b7f0d00e116ee6f3b093e Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Thu, 5 Aug 2021 00:49:08 +0200 Subject: [PATCH] tests: adapt to new linter The Python test driver now uses 'pyflakes'. Remove hacks that were needed for the 'black' linter. --- test/lib/make-test-vm.nix | 30 +++++------------------------- test/tests.py | 9 +++++---- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/test/lib/make-test-vm.nix b/test/lib/make-test-vm.nix index 8742ac2..7ddce50 100644 --- a/test/lib/make-test-vm.nix +++ b/test/lib/make-test-vm.nix @@ -10,36 +10,16 @@ args: let test = pythonTesting.makeTest args; - fixedDriver = test.driver.overrideAttrs (old: let - # Allow the test script to have longer lines by fixing the call to the 'black' - # code formatter. - # The default width of 88 chars is too restrictive for our script. - parts = builtins.split ''/nix/store/[^ ]+/black '' old.buildCommand; - preMatch = builtins.elemAt parts 0; - postMatch = builtins.elemAt parts 2; - in { - # See `mkDriver` in nixpkgs/nixos/lib/testing-python.nix for the original definition of `buildCommand` - buildCommand = '' - ${preMatch}${pkgs.python3Packages.black}/bin/black --line-length 100 ${postMatch} - ''; - # Keep reference to the `testDriver` derivation, required by `buildCommand` - testDriverReference = old.buildCommand; - }); - - # 1. Use fixed driver - # 2. Save test logging output - # 3. Add link to driver so that a gcroot to a test prevents the driver from + # 1. Save test logging output + # 2. Add link to driver so that a gcroot to a test prevents the driver from # being garbage-collected fixedTest = test.overrideAttrs (_: { # See `runTests` in nixpkgs/nixos/lib/testing-python.nix for the original definition of `buildCommand` buildCommand = '' mkdir $out - LOGFILE=$out/output.xml tests='exec(os.environ["testScript"])' ${fixedDriver}/bin/nixos-test-driver - ln -s ${fixedDriver} $out/driver + LOGFILE=$out/output.xml tests='exec(os.environ["testScript"])' ${test.driver}/bin/nixos-test-driver + ln -s ${test.driver} $out/driver ''; - }) // { - driver = fixedDriver; - inherit (test) nodes; - }; + }); in fixedTest diff --git a/test/tests.py b/test/tests.py index 4f8d2fa..a3bb85c 100644 --- a/test/tests.py +++ b/test/tests.py @@ -1,6 +1,7 @@ from collections import OrderedDict import json +logger = machine.logger def succeed(*cmds): """Returns the concatenated output of all cmds""" @@ -39,7 +40,7 @@ def wait_for_open_port(address, port): status, _ = machine.execute(f"nc -z {address} {port}") return status == 0 - with log.nested(f"Waiting for TCP port {address}:{port}"): + with logger.nested(f"Waiting for TCP port {address}:{port}"): retry(is_port_open) @@ -66,7 +67,7 @@ def run_tests(): raise RuntimeError(f"The following tests are enabled but not defined: {enabled}") machine.connect() # Visually separate boot output from the test output for test in to_run: - with log.nested(f"test: {test}"): + with logger.nested(f"test: {test}"): tests[test]() @@ -150,9 +151,9 @@ def _(): f"Output of 'lightning-cli plugin list':\n{plugin_list}" ) else: - log.log("Active clightning plugins:") + logger.log("Active clightning plugins:") for p in test_data["clightning-plugins"]: - log.log(os.path.basename(p)) + logger.log(os.path.basename(p)) @test("lnd")