Do not create *_auto_design.json by default

It's a bad habit to write files into the source code repository. It will
also become impossible if gnpy is installed into a systemwide, possible
read-only location.

The old behavior can be reactivated by using an extra option to tell
GNPy where to put the generated file.

Change-Id: I9ad43890ca5886f516885de5938a4778870a06c5
This commit is contained in:
Jan Kundrát
2020-06-05 19:52:05 +02:00
parent c5c5b693f2
commit 754be7ca08
3 changed files with 20 additions and 15 deletions

View File

@@ -98,6 +98,7 @@ def transmission_main_example(args=None):
default=_examples_dir / 'edfa_example_network.json')
parser.add_argument('source', nargs='?', help='source node')
parser.add_argument('destination', nargs='?', help='destination node')
parser.add_argument('--save-network', type=Path, help='Save the network as a JSON file')
args = parser.parse_args(args if args is not None else sys.argv[1:])
_setup_logging(args)
@@ -255,7 +256,8 @@ def transmission_main_example(args=None):
})
write_csv(result_dicts, 'simulation_result.csv')
save_network(args.filename, network)
if args.save_network is not None:
save_network(network, args.save_network)
if args.show_channels:
print('\nThe total SNR per channel at the end of the line is:')
@@ -317,6 +319,7 @@ def path_requests_run(args=None):
parser.add_argument('-v', '--verbose', action='count', default=0,
help='increases verbosity for each occurence')
parser.add_argument('-o', '--output', type=Path)
parser.add_argument('--save-network', type=Path, help='Save the network as a JSON file')
args = parser.parse_args(args if args is not None else sys.argv[1:])
_setup_logging(args)
@@ -336,7 +339,8 @@ def path_requests_run(args=None):
p_total_db = p_db + lin2db(automatic_nch(equipment['SI']['default'].f_min,
equipment['SI']['default'].f_max, equipment['SI']['default'].spacing))
build_network(network, equipment, p_db, p_total_db)
save_network(args.network_filename, network)
if args.save_network is not None:
save_network(network, args.save_network)
oms_list = build_oms_list(network, equipment)
try:

View File

@@ -316,10 +316,13 @@ def load_network(filename, equipment, name_matching=False):
return network_from_json(json_data, equipment)
def save_network(filename, network):
filename_output = path.splitext(filename)[0] + '_auto_design.json'
json_data = network_to_json(network)
save_json(json_data, filename_output)
def save_network(network: DiGraph, filename: str):
'''Dump the network into a JSON file
:param network: network to work on
:param filename: file to write to
'''
save_json(network_to_json(network), filename)
def _cls_for(equipment_type):

View File

@@ -73,7 +73,7 @@ def test_excel_json_generation(xls_input, expected_json_output):
DATA_DIR / 'testTopology.xls':
DATA_DIR / 'testTopology_auto_design_expected.json',
}.items())
def test_auto_design_generation_fromxlsgainmode(xls_input, expected_json_output):
def test_auto_design_generation_fromxlsgainmode(tmpdir, xls_input, expected_json_output):
""" tests generation of topology json
test that the build network gives correct results in gain mode
"""
@@ -88,9 +88,8 @@ def test_auto_design_generation_fromxlsgainmode(xls_input, expected_json_output)
p_total_db = p_db + lin2db(automatic_nch(equipment['SI']['default'].f_min,
equipment['SI']['default'].f_max, equipment['SI']['default'].spacing))
build_network(network, equipment, p_db, p_total_db)
save_network(xls_input, network)
actual_json_output = xls_input.with_name(xls_input.stem + '_auto_design').with_suffix('.json')
actual_json_output = tmpdir / xls_input.with_name(xls_input.stem + '_auto_design').with_suffix('.json').name
save_network(network, actual_json_output)
with open(actual_json_output, encoding='utf-8') as f:
actual = load(f)
@@ -116,7 +115,7 @@ def test_auto_design_generation_fromxlsgainmode(xls_input, expected_json_output)
DATA_DIR / 'testTopology_auto_design_expected.json':
DATA_DIR / 'testTopology_auto_design_expected.json',
}.items())
def test_auto_design_generation_fromjson(json_input, expected_json_output):
def test_auto_design_generation_fromjson(tmpdir, json_input, expected_json_output):
"""test that autodesign creates same file as an input file already autodesigned
"""
equipment = load_equipment(eqpt_filename)
@@ -130,9 +129,8 @@ def test_auto_design_generation_fromjson(json_input, expected_json_output):
p_total_db = p_db + lin2db(automatic_nch(equipment['SI']['default'].f_min,
equipment['SI']['default'].f_max, equipment['SI']['default'].spacing))
build_network(network, equipment, p_db, p_total_db)
save_network(json_input, network)
actual_json_output = json_input.with_name(json_input.stem + '_auto_design').with_suffix('.json')
actual_json_output = tmpdir / json_input.with_name(json_input.stem + '_auto_design').with_suffix('.json').name
save_network(network, actual_json_output)
with open(actual_json_output, encoding='utf-8') as f:
actual = load(f)