コード例 #1
0
def main():
    if len(sys.argv) < 3:
        return print("Verifique os argumentos", file=sys.stderr)
    else:
        _, file_path, report_type = sys.argv
        importer = {
            ".csv": CsvImporter,
            ".xml": XmlImporter,
            ".json": JsonImporter,
        }
        _, ext = path.splitext(file_path)

        report = InventoryRefactor(importer[ext])
        report = report.import_data(file_path, report_type)
        print(report, end="")
コード例 #2
0
def main():
    if len(sys.argv) < 3:
        return sys.stderr.write("Verifique os argumentos\n")

    path = sys.argv[1]
    file_type = path.split(".")[-1]
    report_type = sys.argv[2]
    file_type_method = {
        "csv": CsvImporter,
        "json": JsonImporter,
        "xml": XmlImporter,
    }

    instance = InventoryRefactor(file_type_method[file_type])
    print(instance.import_data(path, report_type), end="")
コード例 #3
0
def test_validar_enviar_arquivo_extensao_invalida():
    with pytest.raises(ValueError, match="Arquivo inválido"):
        instance = InventoryRefactor(CsvImporter)
        instance.import_data("inventory_report/data/inventory.json", "simples")
コード例 #4
0
def test_validar_iterar_expandir_com_dois_arquivos():
    instance = InventoryRefactor(CsvImporter)
    instance.import_data("inventory_report/data/inventory.csv", "simples")
    instance.importer = JsonImporter
    instance.import_data("inventory_report/data/inventory.json", "simples")
    assert len(instance.data) == 20
コード例 #5
0
def test_validar_iterar_primeiro_item_com_xml():
    instance = InventoryRefactor(XmlImporter)
    instance.import_data("inventory_report/data/inventory.xml", "simples")
    iterator = iter(instance)
    first_item_instance = next(iterator)
    assert DIST == first_item_instance
コード例 #6
0
def test_validar_iterar_primeiro_item_com_json():
    instance = InventoryRefactor(JsonImporter)
    instance.import_data('inventory_report/data/inventory.json', 'simples')
    iterator = iter(instance)
    first_item_instance = next(iterator)
    assert DIST == first_item_instance