Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
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)
Exemple #5
0
def cannot_create_asset_from_asset():
    prep_test_assets()
    a = Asset.get("EN")
    Asset.define(a)
Exemple #6
0
def test_asset_definition():
    clear_all_definitions()
    Asset.define("EN")
    Asset.get("EN")
    Asset["EN"]
Exemple #7
0
def test_asset_not_defined():
    clear_all_definitions()
    Asset.get("EN")
Exemple #8
0
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))
Exemple #9
0
def test_missing_asset_set_key_for_balance():
    prep_test_assets()
    am = AssetAmount(asset=Asset.get("RON"), amount=1)
    ab = AssetBalance()
    ab["YOWZERS"] = am
Exemple #10
0
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"]
Exemple #11
0
def test_asset_balance_set():
    prep_test_assets()
    am = AssetAmount(asset=Asset.get("RON"), amount=1)
    ab = AssetBalance()
    ab[am.asset] = am
Exemple #12
0
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)