mirror of
				https://github.com/Telecominfraproject/oopt-gnpy.git
				synced 2025-11-03 19:47:46 +00:00 
			
		
		
		
	Esther mentioned that it is useful for her to be able to convert from XLS files to JSON files. Let's add a full blown script for this. I've also taken the liberty to refactor the code a bit so that there's no default value, and to modernize everything with pathlib a little bit. Change-Id: I80e50fc1280003910242ce1ff9fc9ae66e6d275b
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.7 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', ]),
 | 
						|
))
 | 
						|
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()
 | 
						|
 | 
						|
 | 
						|
def test_conversion_xls():
 | 
						|
    proc = subprocess.run(
 | 
						|
        ('gnpy-convert-xls', SRC_ROOT / 'tests' / 'data' / 'testTopology.xls', '--output', '/dev/null'),
 | 
						|
        stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, universal_newlines=True)
 | 
						|
    assert proc.stderr == ''
 | 
						|
    assert '/dev/null' in proc.stdout
 |