Skip to content

Commit

Permalink
Updated tests with new assert_footings_audit_xlsx_equal.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustindall committed Aug 3, 2020
1 parent 09c299f commit 9bfdf03
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 405 deletions.
Binary file added tests/core/data/expected-footings-wb.xlsx
Binary file not shown.
Binary file modified tests/core/data/expected-integers.xlsx
Binary file not shown.
Binary file removed tests/core/data/expected-obj-to-xlsx.xlsx
Binary file not shown.
Binary file modified tests/core/data/expected-pandas.xlsx
Binary file not shown.
Binary file removed tests/core/data/expected-xlsx-workbook.xlsx
Binary file not shown.
15 changes: 8 additions & 7 deletions tests/core/test_audit.py
@@ -1,11 +1,10 @@
"""Test for audit.py"""

import os

from footings import build_model
from footings.tools.testing import assert_footings_audit_xlsx_equal

from .shared import STEPS_USING_INTEGERS, STEPS_USING_PANDAS
from .xlsx_helpers import compare_xlsx_files


# def test_audit_json(tmp_path):
# integer_model = create_model("IntegerModel", steps=steps_using_integers())
Expand All @@ -22,12 +21,14 @@ def test_audit_xlsx(tmp_path):
expected_integer_out = os.path.join("tests", "core", "data", "expected-integers.xlsx")
integer_model = build_model("IntegerModel", steps=STEPS_USING_INTEGERS)
loaded_integer_model = integer_model(a=1, b=1, c=1)
loaded_integer_model.audit(output_type="xlsx", file=test_integer_out)
assert compare_xlsx_files(test_integer_out, expected_integer_out, [], {})
loaded_integer_model.audit(file=test_integer_out)

assert_footings_audit_xlsx_equal(test_integer_out, expected_integer_out)

test_pandas_out = os.path.join(tmp_path, "test-pandas.xlsx")
expected_pandas_out = os.path.join("tests", "core", "data", "expected-pandas.xlsx")
pandas_model = build_model("PandasModel", steps=STEPS_USING_PANDAS)
loaded_pandas_model = pandas_model(n=5, add=1, subtract=1)
loaded_pandas_model.audit(output_type="xlsx", file=test_pandas_out)
assert compare_xlsx_files(test_pandas_out, expected_pandas_out, [], {})
loaded_pandas_model.audit(file=test_pandas_out)

assert_footings_audit_xlsx_equal(test_pandas_out, expected_pandas_out)
107 changes: 0 additions & 107 deletions tests/core/test_to_xlsx.py

This file was deleted.

88 changes: 88 additions & 0 deletions tests/core/test_xlsx.py
@@ -0,0 +1,88 @@
import os
import datetime

from attr import attrs, attrib
import pandas as pd

from footings.core.xlsx import FootingsXlsxWb
from footings.tools.testing import assert_footings_audit_xlsx_equal


def test_footings_xlsx_wb(tmp_path):

wb = FootingsXlsxWb.create()

# test builtins
wb.create_sheet("test-builtins", start_row=2, start_col=2)
wb.write_obj("test-builtins", "test-bool", add_cols=1)
wb.write_obj("test-builtins", True, add_rows=1, add_cols=-1)
wb.write_obj("test-builtins", "test-str", add_cols=1)
wb.write_obj("test-builtins", "string", add_rows=1, add_cols=-1)
wb.write_obj("test-builtins", "test-int", add_cols=1)
wb.write_obj("test-builtins", 1, add_rows=1, add_cols=-1)
wb.write_obj("test-builtins", "test-float", add_cols=1)
wb.write_obj("test-builtins", 1.23456789, add_rows=1, add_cols=-1)
wb.write_obj("test-builtins", "test-date", add_cols=1)
wb.write_obj("test-builtins", datetime.date(2018, 12, 31), add_rows=1, add_cols=-1)
wb.write_obj("test-builtins", "test-datetime", add_cols=1)
wb.write_obj(
"test-builtins",
datetime.datetime(2018, 12, 31, 12, 0, 0, 0),
add_rows=1,
add_cols=-1,
)

# test pd.Series
wb.create_sheet("test-series", start_row=2, start_col=2)
wb.write_obj("test-series", pd.Series([1, 2, 3], name="numbers"), add_rows=2)
wb.write_obj("test-series", pd.Series(["a", "b", "c"], name="letters"), add_rows=2)

# test pd.DataFrame
wb.create_sheet("test-dataframe", start_row=2, start_col=2)
df = pd.DataFrame({"numbers": [1, 2], "letters": ["a", "b"]}, None)
wb.write_obj("test-dataframe", df)

# test mapping
wb.create_sheet("test-mapping", start_row=2, start_col=2)
wb.write_obj("test-mapping", {"key": "value"}, add_rows=2)
wb.write_obj("test-mapping", {"key": [1, 2, 3, 4]}, add_rows=2)
wb.write_obj("test-mapping", {"key": df}, add_rows=2)
wb.write_obj("test-mapping", {("tuple", "key"): 1}, add_rows=2)

# test iterable
wb.create_sheet("test-iterable", start_row=2, start_col=2)
wb.write_obj("test-iterable", [1, 2, 3], add_rows=2)
wb.write_obj("test-iterable", [[1, 2, 3], [1, 2, 3]], add_rows=2)
wb.write_obj("test-iterable", [df, df], add_rows=2)

# test custom
@attrs
class CustomOutput:
"""Custom Output"""

a: int = attrib()
b: int = attrib()

def to_audit_xlsx(self):
return {"a": self.a, "b": self.b}

custom1 = CustomOutput(1, 2)
custom2 = CustomOutput(2, 4)

wb.create_sheet("test-custom", start_row=2, start_col=2)
wb.write_obj("test-custom", custom1, add_rows=2)
wb.write_obj("test-custom", custom2, add_rows=2)

# test callable
def test_func(a, b):
return a, b

wb.create_sheet("test-function", start_row=2, start_col=2)
wb.write_obj("test-function", test_func)

test_wb = os.path.join(tmp_path, "test-footings-wb.xlsx")
wb.save(test_wb)

expected_wb = os.path.join("tests", "core", "data", "expected-footings-wb.xlsx")

assert_footings_audit_xlsx_equal(test_wb, expected_wb)

0 comments on commit 9bfdf03

Please sign in to comment.