mirror of
				https://github.com/Telecominfraproject/oopt-gnpy.git
				synced 2025-10-31 01:57:54 +00:00 
			
		
		
		
	 7f816eb6e7
			
		
	
	7f816eb6e7
	
	
	
		
			
			Since Ic4a124a5cbe2bd24c56e4565d27d313fe4da703f, there was no automated test which would check if the generated examples *really* work. When I was playing with this, I managed to break it at least once (especially when working on overriding sys.args, i.e., I53833a5513abae0abd57065a49c0f357890e0820). This now requires an equivalent of `pip install` before the tests can be run. Change-Id: I595a3efe29b3ee13800c5cb71f28a5f370988617
		
			
				
	
	
		
			36 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.4 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,
 | |
|      ['examples/raman_edfa_example_network.json', '--sim', 'examples/sim_params.json', '--show-channels',]),
 | |
| ))
 | |
| 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 == expected
 | |
|     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()
 |