def test_formatting_parsing_nan(): value = float("nan") formatter = Formatter() formatted = formatter(value) parsed = eval(formatted) assert isnan(parsed)
def test_holidata_produces_holidays_for_locale_and_year( snapshot, tmpdir, locale): temp_file = tmpdir.join('{}.{}.py'.format(locale.locale, locale.year)) export_data = [h.as_dict() for h in locale.holidays] export_data.sort(key=lambda x: x['date']) temp_file.write(Formatter().format(export_data, 0)) snapshot.assert_match(FileSnapshot(str(temp_file)))
def test_text_formatting(text_value, expected): formatter = Formatter() formatted = formatter(text_value) assert formatted == expected if six.PY2: # Also check that Python 2 str value formats the same as the unicode value. # (If a test case raises UnicodeEncodeError in here, it should be moved to # the non_ascii verson of this test, below.) py2_str_value = text_value.encode("ASCII") py2_str_formatted = formatter(py2_str_value) assert py2_str_formatted == expected
def test_basic_formatting_parsing(value): formatter = Formatter() formatted = formatter(value) parsed = eval(formatted) assert parsed == value assert type(parsed) == type(value)
def test_can_normalize_iterator_objects(): formatter = Formatter() print(formatter.normalize(x for x in range(3)))
def test_can_normalize_unittest_mock_call_object(): formatter = Formatter() print(formatter.normalize(unittest.mock.call(1, 2, 3)))
def test_non_ascii_text_formatting(text_value, expected): formatter = Formatter() formatted = formatter(text_value) assert formatted == expected
def test_non_ascii_text_formatting(text_value, expected_py3, expected_py2): expected = expected_py2 if six.PY2 else expected_py3 formatter = Formatter() formatted = formatter(text_value) assert formatted == expected
for formatter in Formatter.formatters: if formatter.can_format(value): return formatter :param value: :return: """ return isinstance(value, PandasSnapshot) def store(self, formatter, pandas_snap: PandasSnapshot): """ store pd.DataFrame as bytes in snapshot file""" return pandas_to_bytes(pandas_snap.value) def assert_value_matches_snapshot(self, test, test_value: PandasSnapshot, snapshot_value, formatter): """ :param test: :param test_value: the value in snapshot.assert_mach(value) :param snapshot_value: the value of format.store (after load) """ prev_df = bytes_to_pandas( snapshot_value) # deserialize from bytes to pd.DataFrame timestamp_columns = get_timestamp_columns(test_value.value) nontimestamp_columns = list( set(test_value.value.columns).difference(timestamp_columns)) pd.testing.assert_frame_equal(test_value.value[nontimestamp_columns], prev_df[nontimestamp_columns]) Formatter.register_formatter(PandasFormatter())