def test_equality(): clear_all_definitions() Asset.define("EN") a1 = Asset.get("EN") a2 = Asset.get("EN") assert_true(a1 == a2) assert_true(a1 is a2)
def test_comparisons_and_ident(): prep_test_assets() a = Asset.get("EN") am0 = AssetAmount(asset=a, amount=0) am1 = AssetAmount(asset=a, amount=1) am2 = AssetAmount(asset=a, amount=2) assert_true(am0 < am1) assert_false(am0 > am1) assert_false(am0 >= am1) assert_true(am1 < am2) assert_false(am1 > am2) assert_false(am1 >= am2) assert_true(am1 > am0) assert_false(am1 < am0) assert_false(am1 <= am0) assert_true(am2 > am1) assert_false(am2 < am1) assert_false(am2 <= am1) am3 = AssetAmount(asset=a, amount=0) assert_true(am0 >= am3) assert_true(am0 <= am3) assert_true(am0 == am3) assert_false(am0 != am3) assert_false(am0 is am3)
def test_asset_amount_creation(): prep_test_assets() a = Asset.get("EN") AssetAmount(asset=a, amount="0") AssetAmount(asset=a, amount=1) AssetAmount(asset=a, amount=D(1)) AssetAmount(asset="EN", amount=2)
def test_asset_math(): prep_test_assets() foo = Asset.get("EN") am0 = AssetAmount(asset=foo, amount=0) am1 = AssetAmount(asset=foo, amount=1) am2 = AssetAmount(asset=foo, amount=2) nosetools.eq_(am0 + am2, foo.make_amount(2)) nosetools.eq_(am2 - am1, foo.make_amount(1)) nosetools.eq_(am2 * am2 * am2, foo.make_amount(8)) nosetools.eq_(am2**(am2 + am1), foo.make_amount(8)) nosetools.eq_(am2 / am2, am1) nosetools.eq_(am2 // am2, am1) nosetools.eq_(am2 % am2, am0) nosetools.eq_(-am2, -(am1 + am1)) nosetools.eq_(abs(am0 - am2), am2) nosetools.eq_(+(am0 - am2), am2)
def cannot_create_asset_from_asset(): prep_test_assets() a = Asset.get("EN") Asset.define(a)
def test_asset_definition(): clear_all_definitions() Asset.define("EN") Asset.get("EN") Asset["EN"]
def test_asset_not_defined(): clear_all_definitions() Asset.get("EN")
def test_asset_quote_str_and_repr(): prep_test_assets_and_pairs() aq = ExchangeRate(rate=D(1.0), base=Asset.get("EN"), quote=Asset.get("RON")) logger.info("Found a {0!s} made by {0!r}".format(aq))
def test_missing_asset_set_key_for_balance(): prep_test_assets() am = AssetAmount(asset=Asset.get("RON"), amount=1) ab = AssetBalance() ab["YOWZERS"] = am
def test_asset_balance_keys_by_string(): prep_test_assets() am = AssetAmount(asset=Asset.get("RON"), amount=1) ab = AssetBalance() ab["RON"] = am ab["RON"]
def test_asset_balance_set(): prep_test_assets() am = AssetAmount(asset=Asset.get("RON"), amount=1) ab = AssetBalance() ab[am.asset] = am
def test_cannot_instantiate_from_float_mindlessly(): prep_test_assets() my_fun_val = math.e a = Asset.get("EN") Account.define(name="Donut", asset=a, amount=my_fun_val)