Example #1
0
def test_get_labelled_section(no_init):
    ei = ExcelImporter()
    with pytest.raises(AssertionError):
        assert ei.get_labelled_section(None, [["", ""]])
    with pytest.raises(AssertionError):
        assert ei.get_labelled_section(None, [["foo", "", "bar"]])

    data = [
        ["Parameters", "", "", "", "", "", "", "", "", "", "", "", "", ""],
        [
            "name", "amount", "formula", "", "", "", "", "", "", "", "", "",
            "", ""
        ],
        [
            "something::something",
            0.6,
            "A + B",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
        ],
        [
            "Nope", 1.3, "", "Will be skipped", "", "", "", "", "", "", "", "",
            "", ""
        ],
        ["", "", "", "", "", "", "", "", "", "", "", "", "", ""],
    ]
    expected = [
        {
            "name": "something::something",
            "amount": 0.6,
            "formula": "A + B"
        },
        {
            "name": "Nope",
            "amount": 1.3
        },
    ]
    assert ei.get_labelled_section(None, data, 1, transform=False) == expected
    expected = [
        {
            "name": ("something", "something"),
            "amount": 0.6,
            "formula": "A + B"
        },
        {
            "name": "Nope",
            "amount": 1.3
        },
    ]
    assert ei.get_labelled_section(None, data, 1) == expected
    given = [
        [
            "name", "amount", "formula", "", "", "", "", "", "", "", "", "",
            "", ""
        ],
        [
            "PCB_mass_total",
            0.6,
            "PCB_cap_mass_film + PCB_cap_mass_SMD + PCB_cap_mass_Tantalum",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
        ],
    ]
    expected = [{
        "name":
        "PCB_mass_total",
        "amount":
        0.6,
        "formula":
        "PCB_cap_mass_film + PCB_cap_mass_SMD + PCB_cap_mass_Tantalum",
    }]
    assert ei.get_labelled_section(None, given) == expected
Example #2
0
def test_get_labelled_section(no_init):
    ei = ExcelImporter()
    with pytest.raises(AssertionError):
        assert ei.get_labelled_section(None, [['', '']])
    with pytest.raises(AssertionError):
        assert ei.get_labelled_section(None, [['foo', '', 'bar']])

    data = [
        ['Parameters', '', '', '', '', '', '', '', '', '', '', '', '', ''],
        [
            'name', 'amount', 'formula', '', '', '', '', '', '', '', '', '',
            '', ''
        ],
        [
            'something::something', 0.6, 'A + B', '', '', '', '', '', '', '',
            '', '', '', ''
        ],
        [
            'Nope', 1.3, '', 'Will be skipped', '', '', '', '', '', '', '', '',
            '', ''
        ],
        ['', '', '', '', '', '', '', '', '', '', '', '', '', ''],
    ]
    expected = [{
        'name': 'something::something',
        'amount': 0.6,
        'formula': 'A + B'
    }, {
        'name': 'Nope',
        'amount': 1.3
    }]
    assert ei.get_labelled_section(None, data, 1, transform=False) == expected
    expected = [{
        'name': ("something", "something"),
        'amount': 0.6,
        'formula': 'A + B'
    }, {
        'name': 'Nope',
        'amount': 1.3
    }]
    assert ei.get_labelled_section(None, data, 1) == expected
    given = [
        [
            'name', 'amount', 'formula', '', '', '', '', '', '', '', '', '',
            '', ''
        ],
        [
            'PCB_mass_total', 0.6,
            'PCB_cap_mass_film + PCB_cap_mass_SMD + PCB_cap_mass_Tantalum', '',
            '', '', '', '', '', '', '', '', '', ''
        ]
    ]
    expected = [{
        'name':
        'PCB_mass_total',
        'amount':
        0.6,
        'formula':
        'PCB_cap_mass_film + PCB_cap_mass_SMD + PCB_cap_mass_Tantalum'
    }]
    assert ei.get_labelled_section(None, given) == expected