def test_assert_equal(self): fa_util.assert_equal(1 + 1, 2) with self.assertRaises(AssertionError) as cm: fa_util.assert_equal(1 + 1, 1) self.assertEqual(str(cm.exception), "The variable is expected to be 1 but is actually 2")
def _validate(obj, actual_currency, symbol, timeframe, report_type): """ Verifies whether <obj> is good for value parsing. obj: dictionary of scraped raw data actual_currency: currency used, derived from <obj> symbol, timeframe, report_type: the parameters that were used to obtain <obj> """ prefix, _, suffix = symbol.partition('.') # symbol, timeframe, report_type assert_equal(obj["symbol_prefix"], prefix, "symbol prefix") assert_equal(obj["timeframe"], timeframe, "timeframe") assert_equal(obj["report_type"], report_type, "report_type") # currency expected_currency = SYMBOL_SUFFIX_INFO[suffix][2] if suffix else DEFAULT_CURRENCY if actual_currency != expected_currency: # currency is not so important in fundamental analysis logger.warning("currency is expected to be {0} but is actually {1}".format(expected_currency, actual_currency)) # first column's name data = obj["data"] assert_equal(data[0][0], "periods", "first column's name") # uniqueness of periods periods = data[0][1] assert len(periods) == len(set(periods)), "Periods are expected to be unique, but they are not" # column length column_lengths = set(len(p[1]) for p in data) assert len(column_lengths) == 1, "All columns are expected to have the same length, but they do not"