Files
oopt-gnpy/tests/test_invocation.py
Jan Kundrát 797a0856ec tests: Use a portable /dev/null file name
Bug: https://github.com/Telecominfraproject/oopt-gnpy/issues/358
Change-Id: Icbca94682ce0ded860ba6397e4445651b6a61f32
2021-06-17 16:20:49 +02:00

46 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
from pathlib import Path
import os
import pytest
import subprocess
from gnpy.tools.cli_examples import transmission_main_example, path_requests_run
SRC_ROOT = Path(__file__).parent.parent
@pytest.mark.parametrize("output, handler, args", (
('transmission_main_example', transmission_main_example, []),
('path_requests_run', path_requests_run, []),
('transmission_main_example__raman', transmission_main_example,
['gnpy/example-data/raman_edfa_example_network.json', '--sim', 'gnpy/example-data/sim_params.json', '--show-channels', ]),
('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):
'''Make sure that our examples produce useful output'''
os.chdir(SRC_ROOT)
expected = open(SRC_ROOT / 'tests' / 'invocation' / output, mode='rb').read()
handler(args)
captured = capfdbinary.readouterr()
assert captured.out.decode('utf-8') == expected.decode('utf-8')
assert captured.err == b''
@pytest.mark.parametrize('program', ('gnpy-transmission-example', 'gnpy-path-request'))
def test_run_wrapper(program):
'''Ensure that our wrappers really, really work'''
proc = subprocess.run((program, '--help'), stdout=subprocess.PIPE, stderr=subprocess.PIPE,
check=True, universal_newlines=True)
assert proc.stderr == ''
assert 'https://github.com/telecominfraproject/oopt-gnpy' in proc.stdout.lower()
assert 'https://gnpy.readthedocs.io/' in proc.stdout.lower()
def test_conversion_xls():
proc = subprocess.run(
('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 os.path.devnull in proc.stdout