Exemplo n.º 1
0
def test_eqpt_creation(tmpdir):
    """ tests that convert correctly creates equipment according to equipment sheet
    including all cominations in testTopologyconvert.xls: if a line exists the amplifier
    should be created even if no values are provided.
    """
    xls_input = DATA_DIR / 'testTopologyconvert.xls'

    xls_copy = Path(tmpdir) / xls_input.name
    shutil.copyfile(xls_input, xls_copy)
    convert_file(xls_copy)

    actual_json_output = xls_copy.with_suffix('.json')
    actual = load_json(actual_json_output)
    unlink(actual_json_output)

    connections = {
        elem['from_node']: elem['to_node']
        for elem in actual['connections']
    }
    jsonconverted = {}
    for elem in actual['elements']:
        if 'type' in elem.keys() and elem['type'] == 'Edfa':
            print(elem['uid'])
            if 'type_variety' in elem.keys():
                jsonconverted[elem['uid']] = Amp(elem['uid'],
                                                 connections[elem['uid']],
                                                 elem['type_variety'])
            else:
                jsonconverted[elem['uid']] = Amp(elem['uid'],
                                                 connections[elem['uid']])

    with open_workbook(xls_input) as wobo:
        # reading Eqpt sheet assuming header is node A, Node Z, amp variety
        # fused should not be recorded as an amp
        eqpt_sheet = wobo.sheet_by_name('Eqpt')
        raw_eqpts = {}
        for row in all_rows(eqpt_sheet, start=5):
            if row[0].value not in raw_eqpts.keys():
                raw_eqpts[row[0].value] = Amp(row[0].value, [row[1].value],
                                              [row[2].value], [row[7].value])
            else:
                raw_eqpts[row[0].value].to_node.append(row[1].value)
                raw_eqpts[row[0].value].eqpt.append(row[2].value)
                raw_eqpts[row[0].value].west.append(row[7].value)
    # create the possible names similarly to what convert should do
    possiblename = [f'east edfa in {xlsname} to {node}' for xlsname, value in raw_eqpts.items()
                    for i, node in enumerate(value.to_node) if value.eqpt[i] != 'fused'] +\
                   [f'west edfa in {xlsname} to {node}' for xlsname, value in raw_eqpts.items()
                    for i, node in enumerate(value.to_node) if value.west[i] != 'fused']
    # check that all lines in eqpt sheet correctly converts to an amp element
    for name in possiblename:
        assert name in jsonconverted.keys()
    # check that all amp in the converted files corresponds to an eqpt line
    for ampuid in jsonconverted.keys():
        assert ampuid in possiblename
Exemplo n.º 2
0
def test_excel_json_generation(tmpdir, xls_input, expected_json_output):
    """ tests generation of topology json
    """
    xls_copy = Path(tmpdir) / xls_input.name
    shutil.copyfile(xls_input, xls_copy)
    convert_file(xls_copy)

    actual_json_output = xls_copy.with_suffix('.json')
    actual = load_json(actual_json_output)
    unlink(actual_json_output)
    assert actual == load_json(expected_json_output)
Exemplo n.º 3
0
def test_excel_json_generation(tmpdir, xls_input, expected_json_output):
    """ tests generation of topology json
    """
    xls_copy = Path(tmpdir) / xls_input.name
    shutil.copyfile(xls_input, xls_copy)
    convert_file(xls_copy)

    actual_json_output = xls_copy.with_suffix('.json')
    actual = load_json(actual_json_output)
    unlink(actual_json_output)
    expected = load_json(expected_json_output)

    results = compare_networks(expected, actual)
    assert not results.elements.missing
    assert not results.elements.extra
    assert not results.elements.different
    assert not results.connections.missing
    assert not results.connections.extra
    assert not results.connections.different