From 3fa53adc4d6cc4939f652739ffd4b791b42dc5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Thu, 17 Jun 2021 16:20:38 +0200 Subject: [PATCH 1/4] Don't print file name when handling requests We have a test which compares the raw output of GNPy against a fixed expected output. That comparison of course chokes when forward slashes and backslashes are used, which breaks the test suite on Windows. Let's try to solve this by always using forward slashes if possible. The way to go is via pathlib's as_posix(), but that one can possibly return an absolute path -- which cannot work in a test suite, obviously. So one can workaround that via calling a Path.relative_to(), but that one chokes on paths which require at least one "path up" component (`..`). I posted a patch which use brute force here, but Jonas is right, better just don't print that output in the test suite in the first place. Change-Id: I762ddb58a2042120c7b20414152a06a3ed72048d Bug: https://github.com/Telecominfraproject/oopt-gnpy/issues/358 --- gnpy/tools/cli_examples.py | 1 - tests/invocation/path_requests_run | 1 - 2 files changed, 2 deletions(-) diff --git a/gnpy/tools/cli_examples.py b/gnpy/tools/cli_examples.py index 5dfa9212..fb311ed7 100644 --- a/gnpy/tools/cli_examples.py +++ b/gnpy/tools/cli_examples.py @@ -306,7 +306,6 @@ def path_requests_run(args=None): _setup_logging(args) _logger.info(f'Computing path requests {args.service_filename} into JSON format') - print(f'{ansi_escapes.blue}Computing path requests {os.path.relpath(args.service_filename)} into JSON format{ansi_escapes.reset}') (equipment, network) = load_common_data(args.equipment, args.topology, args.sim_params, args.save_network_before_autodesign) diff --git a/tests/invocation/path_requests_run b/tests/invocation/path_requests_run index b75a0c6a..78348ce9 100644 --- a/tests/invocation/path_requests_run +++ b/tests/invocation/path_requests_run @@ -1,4 +1,3 @@ -Computing path requests gnpy/example-data/meshTopologyExampleV2.xls into JSON format List of disjunctions [Disjunction 3 relaxable: false From 797a0856ecfc0d0229e773b4853b2bbd14574d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Tue, 15 Jun 2021 13:30:54 +0200 Subject: [PATCH 2/4] tests: Use a portable /dev/null file name Bug: https://github.com/Telecominfraproject/oopt-gnpy/issues/358 Change-Id: Icbca94682ce0ded860ba6397e4445651b6a61f32 --- tests/test_invocation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_invocation.py b/tests/test_invocation.py index 0c100011..41c3e3ed 100644 --- a/tests/test_invocation.py +++ b/tests/test_invocation.py @@ -39,7 +39,7 @@ def test_run_wrapper(program): def test_conversion_xls(): proc = subprocess.run( - ('gnpy-convert-xls', SRC_ROOT / 'tests' / 'data' / 'testTopology.xls', '--output', '/dev/null'), + ('gnpy-convert-xls', SRC_ROOT / 'tests' / 'data' / 'testTopology.xls', '--output', os.path.devnull), stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, universal_newlines=True) assert proc.stderr == '' - assert '/dev/null' in proc.stdout + assert os.path.devnull in proc.stdout From 55932ee3e9f29d9b45593c8e58179929fe448257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Thu, 17 Jun 2021 16:56:07 +0200 Subject: [PATCH 3/4] tests: handle Unicode properly for "expected console output" Let's use the text mode everywhere because Unicode codepoints is what matters. The only catch on Windows turned out to be the default file IO encoding; forcing UTF-8 there fixes all issues in the CI (and it makes sense because that file was written out in a UTF-8 locale, and the system which runs the test suite might be set to something else. This was a rather interesting debugging experience; passing logs over the web and handling "strange" characters as utf-8 did not help. Change-Id: I1fdbe3a115458558b27a81f9eab8e58c9605bae7 Bug: https://github.com/Telecominfraproject/oopt-gnpy/issues/358 --- tests/test_invocation.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_invocation.py b/tests/test_invocation.py index 41c3e3ed..66bf3cd4 100644 --- a/tests/test_invocation.py +++ b/tests/test_invocation.py @@ -17,14 +17,14 @@ SRC_ROOT = Path(__file__).parent.parent ('openroadm-Stockholm-Gothenburg', transmission_main_example, ['-e', 'gnpy/example-data/eqpt_config_openroadm.json', 'gnpy/example-data/Sweden_OpenROADM_example_network.json', ]), )) -def test_example_invocation(capfdbinary, output, handler, args): +def test_example_invocation(capfd, output, handler, args): '''Make sure that our examples produce useful output''' os.chdir(SRC_ROOT) - expected = open(SRC_ROOT / 'tests' / 'invocation' / output, mode='rb').read() + expected = open(SRC_ROOT / 'tests' / 'invocation' / output, mode='r', encoding='utf-8').read() handler(args) - captured = capfdbinary.readouterr() - assert captured.out.decode('utf-8') == expected.decode('utf-8') - assert captured.err == b'' + captured = capfd.readouterr() + assert captured.out == expected + assert captured.err == '' @pytest.mark.parametrize('program', ('gnpy-transmission-example', 'gnpy-path-request')) From 0cf45bd10213240612b2f24e38e5d4fa5f440ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Tue, 15 Jun 2021 09:54:06 +0200 Subject: [PATCH 4/4] CI: test on Windows I've been getting reports that the test suite is broken on Windows (the usual set of problems such as CRLF line endings and backslashes in path names), so let's make sure we have a way of reproducing this. Unfortunately, we don't have a Windows image in Zuul, so this will be a post-merge CI I'm afraid :(. Change-Id: Ibd539764d6e40693b95a9b231324bd0216e4a207 --- .github/workflows/main.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5a9ba78b..3d624ae3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -85,3 +85,22 @@ jobs: push: true tags: | telecominfraproject/oopt-gnpy:${{ steps.extract_tag_name.outputs.GIT_DESC }} + + windows: + name: Tests on Windows + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python_version }} + - run: | + pip install --editable . + pip install 'pytest>=5.0.0,<6' + pytest -vv + strategy: + matrix: + python_version: + - "3.9"