def test_init(): t = multiclass.Test(5, 2) assert t.room == 5 assert t.floor == 2 with pytest.raises(TypeError): tt = multiclass.Test('fail!', 5.5) t2 = multiclass.Test2(8.8, 30, t) assert t2.name == 8.8 assert t2.age == 30 assert t2.foo == t with pytest.raises(TypeError): tt2 = multiclass.Test2(6, 6, 6)
def test_access(): t = multiclass.Test(5, 2) assert t['room'] == 5 t['floor'] = 10 assert t.floor == 10 t.room = 100 assert t['room'] == 100
def test_any_mutation(): t = multiclass.Test(5, 2) t2 = multiclass.Test2(8.8, 30, t) s = "I can be a string!" t2.name = s assert t2.name == s lst = [1, ''] t2.name = lst assert t2.name == lst
def test_ujson_dumps_speed(benchmark): n = multiclass.Test(4211, 4) d = ujson.loads(multiclass.dumps(n)) benchmark(ujson.dumps, d)
def test_ujson_loads_speed(benchmark): n = multiclass.Test(4211, 4) s = multiclass.dumps(n) benchmark(ujson.loads, s)
def test_abserde_loads_speed(benchmark): n = multiclass.Test(4211, 4) s = multiclass.dumps(n) benchmark(multiclass.Test.loads, s)
def test_abserde_dumps_speed(benchmark): n = multiclass.Test(4211, 4) benchmark(n.dumps)
def test_str(): t = multiclass.Test(5, 2) assert(str(t) == t.dumps())
def test_dumps(): t = multiclass.Test(5, 2) assert t.dumps() == '{"room":5,"floor":2}' t2 = multiclass.Test2(8.8, 30, t) assert t2.dumps() == '{"name":8.8,"age":30,"foo":{"room":5,"floor":2}}'