Example #1
0
def test_csvdb_all_reports(clean_csv_files):
    """
    Test create/save/read all kind of reports
    """
    all_reports = [(PowerModel(), gen_power_report),
                   (HWPCModel(), gen_hwpc_report)]

    for model, generator in all_reports:
        # Load DB
        csvdb = CsvDB(current_path=PATH_TO_SAVE)
        csvdb.connect()

        # Create report
        report = generator()

        # Save report
        csvdb.save(report, model)

        # Read report
        for r, d, f in os.walk(PATH_TO_SAVE + report.sensor + "-" + report.target + "/"):
            for file in f:
                if '.csv' in file:
                    csvdb.add_file(os.path.join(r, file))
        csvdb_iter = csvdb.iter(model, False)
        read_report = next(csvdb_iter)

        # Compare
        assert read_report == report
Example #2
0
    def test_csvdb_save_on(self, clean_csv_files):
        """
        Save a PowerReport from an basic object
        """
        csvdb = CsvDB(current_path=PATH_TO_SAVE)
        csvdb.connect()

        power_reports = list()

        # Save one time with a file that doesn't exist
        power_reports.append(gen_power_report())
        csvdb.save(power_reports[0], PowerModel())

        # Save three time
        for _ in range(3):
            power_reports.append(gen_power_report())
            csvdb.save(power_reports[-1], PowerModel())

        # Read the the csvdb and compare the data
        reading_power_reports = []
        csvdb_read = CsvDB(current_path=PATH_TO_SAVE)
        csvdb_read.add_file(PATH_TO_SAVE + SENSOR + "-" + TARGET + "/PowerReport.csv")
        csvdb_read.connect()
        csvdb_read_iter = csvdb_read.iter(PowerModel(), False)

        for _ in range(4):
            reading_power_reports.append(next(csvdb_read_iter))

        with pytest.raises(StopIteration) as pytest_wrapped:
            next(csvdb_read_iter)
        assert pytest_wrapped.type == StopIteration

        for i in range(4):
            assert power_reports[i] == reading_power_reports[i]