Esempio n. 1
0
def test_20_million_insert_of_invoices(random_invoices):
    invoice_stats = InvoiceStats()
    t_insert_20_million_rows = process_time()
    invoice_stats.add_invoices(invoices=random_invoices)
    elapsed_time_insert_20_million_rows = process_time() - t_insert_20_million_rows

    LOGGER.info(
        f"elapsed_time_insert_20_million_rows: {elapsed_time_insert_20_million_rows} seconds"
    )

    invoice_stats.invoice_schema.validate(invoice_stats.invoices)

    t_get_median_20_million_rows = process_time()
    invoice_stats.get_median()
    elapsed_time_get_median_20_million_rows = process_time() - t_get_median_20_million_rows

    LOGGER.info(
        f"elapsed_time_get_median_20_million_rows: {elapsed_time_get_median_20_million_rows} seconds"
    )

    t_get_mean_20_million_rows = process_time()
    invoice_stats.get_mean()
    elapsed_time_get_mean_20_million_rows = process_time() - t_get_mean_20_million_rows

    LOGGER.info(f"elapsed_time_get_mean_20_million_rows: {elapsed_time_get_mean_20_million_rows}")

    LOGGER.info(f"\n{invoice_stats.invoice_stats.to_string()}\n")

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.shape[0] == 1
    assert invoice_stats.invoice_stats.shape[1] == 2

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == INVOICE_LIMIT
    assert invoice_stats.invoices.shape[1] == 2
Esempio n. 2
0
def test_get_mean_failure(incorrect_invoice):
    invoice_stats = InvoiceStats()
    invoice_stats.add_invoice(incorrect_invoice)

    # force wrong value
    invoice_stats.invoices["invoice_value"] = "abc"

    with pytest.raises(Exception):
        invoice_stats.get_mean()
Esempio n. 3
0
def test_set_agg_value_invoice_values_failure(incorrect_invoice):
    invoice_stats = InvoiceStats()

    invoice_stats.add_invoice(invoice=incorrect_invoice)

    # force wrong value
    invoice_stats.invoices["invoice_value"] = "abc"

    with pytest.raises(Exception):
        invoice_stats._set_agg_value_invoice_values(row=0,
                                                    column="asdasd",
                                                    agg_type="mean")
Esempio n. 4
0
def invoice_instance(
    mock_pandas,
    mock_valid_min_invoice_val,
    mock_valid_max_invoice_val,
    mock_valid_invoice_limit,
    mock_create_invoice_schema,
    mock_create_invoice_stats_schema,
) -> Generator[InvoiceStats, None, None]:
    """PyTest fixture to create invoice instance to use in tests"""
    invoice_stats: InvoiceStats = InvoiceStats(
        max_invoice_value=MAX_VALUE, min_invoice_value=MIN_VALUE, invoice_limit=LIMIT,
    )

    yield invoice_stats
def test_mean_and_median_of_invoices(random_invoices, expected_mean, expected_median):
    invoice_stats = InvoiceStats()

    invoice_stats.add_invoices(invoices=random_invoices)

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == len(random_invoices)
    assert invoice_stats.invoices.shape[1] == 2

    invoice_stats.get_mean()
    invoice_stats.get_median()

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.shape[0] == 1
    assert invoice_stats.invoice_stats.shape[1] == 2

    # Validate that mean and median is correct
    LOGGER.info(
        f"{invoice_stats.invoice_stats.values.tolist()[0]} == {[expected_mean, expected_median]}"
    )
    assert invoice_stats.invoice_stats.values.tolist()[0] == [expected_mean, expected_median]
Esempio n. 6
0
def test_add_remove_add(random_invoice, random_invoices, expected_mean, expected_median):
    invoice_stats = InvoiceStats()

    invoice_stats.add_invoices(invoices=random_invoices)

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == len(random_invoices)
    assert invoice_stats.invoices.shape[1] == 2

    invoice_stats.get_mean()
    invoice_stats.get_median()

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.shape[0] == 1
    assert invoice_stats.invoice_stats.shape[1] == 2

    invoice_stats.add_invoice(invoice=random_invoice)

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == len(random_invoices) + 1
    assert invoice_stats.invoices.shape[1] == 2

    invoice_stats.clear()

    # Check dimension of invoices
    assert invoice_stats.invoices.empty
    assert invoice_stats.invoices.empty

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.empty
    assert invoice_stats.invoice_stats.empty

    invoice_stats.add_invoice(invoice=random_invoice)

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == 1
    assert invoice_stats.invoices.shape[1] == 2

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.empty
    assert invoice_stats.invoice_stats.empty

    invoice_stats.get_mean()
    invoice_stats.get_median()

    assert invoice_stats.invoice_stats.values.tolist()[0] == [999.0, 999.0]
Esempio n. 7
0
def test_insert_failure(incorrect_invoices):
    invoice_stats = InvoiceStats()
    with pytest.raises(SchemaError):
        invoice_stats.add_invoices(invoices=incorrect_invoices)