mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-10-29 17:22:42 +00:00
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:
BIN
tests/data/create_eqpt_sheet/testTopology.xls
Normal file
BIN
tests/data/create_eqpt_sheet/testTopology.xls
Normal file
Binary file not shown.
34
tests/data/create_eqpt_sheet/testTopology_eqpt_sheet.csv
Normal file
34
tests/data/create_eqpt_sheet/testTopology_eqpt_sheet.csv
Normal 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
|
||||
|
BIN
tests/data/create_eqpt_sheet/test_ces_key_err.xls
Normal file
BIN
tests/data/create_eqpt_sheet/test_ces_key_err.xls
Normal file
Binary file not shown.
BIN
tests/data/create_eqpt_sheet/test_ces_no_err.xls
Normal file
BIN
tests/data/create_eqpt_sheet/test_ces_no_err.xls
Normal file
Binary file not shown.
BIN
tests/data/create_eqpt_sheet/test_ces_node_degree_err.xls
Normal file
BIN
tests/data/create_eqpt_sheet/test_ces_node_degree_err.xls
Normal file
Binary file not shown.
9
tests/data/create_eqpt_sheet/test_create_eqpt_sheet.csv
Normal file
9
tests/data/create_eqpt_sheet/test_create_eqpt_sheet.csv
Normal 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
|
||||
|
95
tests/test_create_eqpt_sheet.py
Normal file
95
tests/test_create_eqpt_sheet.py
Normal 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)
|
||||
Reference in New Issue
Block a user