def test_anonymous(self): alias = ClassAlias(Spam, defer=True) miniamf.CLASS_CACHE['foo'] = alias miniamf.CLASS_CACHE[Spam] = alias self.assertTrue(alias.anonymous) ret = miniamf.unregister_class(Spam) self.assertTrue('foo' in miniamf.CLASS_CACHE) self.assertFalse(Spam in miniamf.CLASS_CACHE) self.assertTrue(ret is alias)
def test_static(self): alias = miniamf.register_class(Spam, 'abc.xyz') alias.dynamic = False x = Spam({'spam': 'eggs'}) self.encoder.writeElement(x) self.assertEqual(self.buf.getvalue(), b'\n\x03\x0fabc.xyz') miniamf.unregister_class(Spam) self.buf.truncate() self.buf.seek(0, 0) self.encoder.context.clear() alias = miniamf.register_class(Spam, 'abc.xyz') alias.dynamic = False alias.static_attrs = ['spam'] x = Spam({'spam': 'eggs', 'foo': 'bar'}) self.encoder.writeElement(x) self.assertEqual(self.buf.getvalue(), b'\n\x13\x0fabc.xyz\tspam\x06\teggs')
def test_alias(self): self.assertFalse('foo' in miniamf.CLASS_CACHE) with self.assertRaises(miniamf.UnknownClassAlias): miniamf.unregister_class('foo')
def tearDown(self): EncoderMixIn.tearDown(self) miniamf.unregister_class(self.TestObject) miniamf.unregister_class(self.TestSubObject)