Move and refactor create_eqpt_sheet.py and add tests on it

Co-authored-by: Rodrigo Sasse David <rodrigo.sassedavid@orange.com>

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
Change-Id: Ib961c5c0e203f2225a0f1e2e7a091485567189c3
This commit is contained in:
EstherLerouzic
2021-11-04 15:56:01 +01:00
parent 0bc1fb3bf8
commit a0758d0da5
10 changed files with 288 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,34 @@
node_a,node_z,amp_type,att_in,amp_gain,tilt,att_out,delta_p,amp_type,att_in,amp_gain,tilt,att_out,delta_p
Lannion_CAS,Corlay
Lannion_CAS,Stbrieuc
Lannion_CAS,Morlaix
Lorient_KMA,Loudeac
Lorient_KMA,Vannes_KBE
Lorient_KMA,Quimper
Vannes_KBE,Lorient_KMA
Vannes_KBE,Ploermel
Stbrieuc,Lannion_CAS
Rennes_STA,Stbrieuc
Rennes_STA,Ploermel
Brest_KLA,Morlaix
Brest_KLA,Quimper
Quimper,Brest_KLA
Ploermel,Vannes_KBE
a,b
a,c
b,a
b,f
c,a
c,d
c,f
d,c
d,e
f,c
f,b
f,h
e,d
e,g
g,e
g,h
h,f
h,g
1 node_a,node_z,amp_type,att_in,amp_gain,tilt,att_out,delta_p,amp_type,att_in,amp_gain,tilt,att_out,delta_p
2 Lannion_CAS,Corlay
3 Lannion_CAS,Stbrieuc
4 Lannion_CAS,Morlaix
5 Lorient_KMA,Loudeac
6 Lorient_KMA,Vannes_KBE
7 Lorient_KMA,Quimper
8 Vannes_KBE,Lorient_KMA
9 Vannes_KBE,Ploermel
10 Stbrieuc,Lannion_CAS
11 Rennes_STA,Stbrieuc
12 Rennes_STA,Ploermel
13 Brest_KLA,Morlaix
14 Brest_KLA,Quimper
15 Quimper,Brest_KLA
16 Ploermel,Vannes_KBE
17 a,b
18 a,c
19 b,a
20 b,f
21 c,a
22 c,d
23 c,f
24 d,c
25 d,e
26 f,c
27 f,b
28 f,h
29 e,d
30 e,g
31 g,e
32 g,h
33 h,f
34 h,g

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,9 @@
node_a,node_z,amp_type,att_in,amp_gain,tilt,att_out,delta_p,amp_type,att_in,amp_gain,tilt,att_out,delta_p
a,b
a,d
a,e
c,b
c,d
c,e
d,c
e,a
1 node_a,node_z,amp_type,att_in,amp_gain,tilt,att_out,delta_p,amp_type,att_in,amp_gain,tilt,att_out,delta_p
2 a,b
3 a,d
4 a,e
5 c,b
6 c,d
7 c,e
8 d,c
9 e,a

View File

@@ -0,0 +1,95 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: BSD-3-Clause
# test_create_eqpt_sheet
# Copyright (C) 2025 Telecom Infra Project and GNPy contributors
# see AUTHORS.rst for a list of contributors
"""
Checks create_eqpt_sheet.py: verify that output is as expected
"""
from pathlib import Path
from os import symlink, unlink
import pytest
from gnpy.tools.create_eqpt_sheet import Node, read_excel, create_eqpt_template
from gnpy.core.exceptions import NetworkTopologyError
TEST_DIR = Path(__file__).parent
DATA_DIR = TEST_DIR / 'data' / 'create_eqpt_sheet'
TEST_FILE_NO_ERR = DATA_DIR / 'test_ces_no_err.xls'
TEST_FILE = 'testTopology.xls'
EXPECTED_OUTPUT = DATA_DIR / 'testTopology_eqpt_sheet.csv'
TEST_FILE_NODE_DEGREE_ERR = DATA_DIR / 'test_ces_node_degree_err.xls'
TEST_FILE_KEY_ERR = DATA_DIR / 'test_ces_key_err.xls'
TEST_OUTPUT_FILE_CSV = DATA_DIR / 'test_create_eqpt_sheet.csv'
PYTEST_OUTPUT_FILE_NAME = 'test_ces_pytest_output.csv'
EXPECTED_OUTPUT_CSV_NAME = 'testTopology_eqpt_sheet.csv'
@pytest.fixture()
def test_node():
"""Fixture of simple Node."""
return Node(1, ['A', 'B'], 'ROADM')
@pytest.fixture()
def test_nodes_list():
"""Fixture of nodes list parsing."""
return read_excel(TEST_FILE_NO_ERR)
def test_node_append(test_node):
"""Test Node's append method."""
expected = {'uid': 1, 'to_node': ['A', 'B', 'C'], 'eqpt': 'ROADM'}
test_node.to_node.append('C')
assert test_node.__dict__ == expected
def test_read_excel(test_nodes_list):
"""Test method read_excel()."""
expected = {}
expected['a'] = Node('a', ['b', 'd', 'e'], 'ROADM')
expected['b'] = Node('b', ['a', 'c'], 'FUSED')
expected['c'] = Node('c', ['b', 'd', 'e'], 'ROADM')
expected['d'] = Node('d', ['c', 'a'], 'ILA')
expected['e'] = Node('e', ['a', 'c'], 'ILA')
assert set(test_nodes_list) == set(expected)
def test_read_excel_node_degree_err():
"""Test node degree error (eqpt == 'ILA' and len(nodes[node].to_node) != 2)."""
with pytest.raises(NetworkTopologyError):
_ = read_excel(TEST_FILE_NODE_DEGREE_ERR)
def test_read_excel_key_err():
"""Test node not listed on the links sheets."""
with pytest.raises(NetworkTopologyError):
_ = read_excel(TEST_FILE_KEY_ERR)
def test_create_eqpt_template(tmpdir, test_nodes_list):
"""Test method create_eqt_template()."""
create_eqpt_template(test_nodes_list, DATA_DIR / TEST_FILE_NO_ERR,
tmpdir / PYTEST_OUTPUT_FILE_NAME)
with open((tmpdir / PYTEST_OUTPUT_FILE_NAME).strpath, 'r') as actual, \
open(TEST_OUTPUT_FILE_CSV, 'r') as expected:
assert set(actual.readlines()) == set(expected.readlines())
unlink(tmpdir / PYTEST_OUTPUT_FILE_NAME)
def test_create_eqpt(tmpdir):
"""Test method create_eqt_template()."""
# create a fake file in tempdir in order to test the automatic output filename generation
symlink(DATA_DIR / TEST_FILE, tmpdir / TEST_FILE)
create_eqpt_template(read_excel(DATA_DIR / TEST_FILE), Path((tmpdir / TEST_FILE).strpath))
with open(DATA_DIR / EXPECTED_OUTPUT_CSV_NAME, 'r') as expected, \
open(tmpdir / EXPECTED_OUTPUT_CSV_NAME, 'r') as actual:
assert set(actual.readlines()) == set(expected.readlines())
unlink(tmpdir / EXPECTED_OUTPUT_CSV_NAME)