예제 #1
0
    def test_attribute_addition(self):
        editor = codegen.ItemEditor('tests.schema.TestItem')
        editor.set_property('y', 1)
        editor.commit_changes()

        item = schema.TestItem()
        self.assertEqual(item.y, 1)
예제 #2
0
    def test_datatype_addition_with_default_value(self):
        editor = codegen.ItemEditor('tests.schema.TestItem')
        editor.set_property('z', datatypes.String(value='Test'))
        editor.commit_changes()

        item = schema.TestItem()
        self.assertEqual(item.z.value, 'Test')
예제 #3
0
    def test_external_datatype_addition(self):
        editor = codegen.ItemEditor('tests.schema.TestItem')
        editor.set_property('ex', ExternalDatatype())
        editor.commit_changes()

        item = schema.TestItem()
        self.assertEqual(item.ex.value, '')
예제 #4
0
 def test_compiled_module_filename(self):
     editor = codegen.ItemEditor('tests.schema.TestItem')
     editor._module.__file__ += 'c'
     try:
         editor.commit_changes()
     finally:
         editor._module.__file__ = editor._module.__file__[:-1]
예제 #5
0
    def test_datatype_removal(self):
        editor = codegen.ItemEditor('tests.schema.TestItem')
        editor.remove_property('z')
        editor.commit_changes()

        item = schema.TestItem()
        self.assertRaises(AttributeError, getattr, item, 'z')
예제 #6
0
    def test_event_handlers(self):
        editor = codegen.ItemEditor('tests.schema.TestFolder')
        editor._eventHandlers.append(schema.TestEventHandler)
        editor.commit_changes()

        folder = schema.TestFolder()
        self.assertEqual(folder._eventHandlers, [schema.TestEventHandler])
예제 #7
0
    def test_generic_item(self):
        editor = codegen.ItemEditor('tests.schema.TestGenericItem')
        editor.set_property('z', datatypes.String())
        editor.commit_changes()

        item = schema.TestGenericItem()
        self.assertEqual(item.z.value, '')
        self.assertNotEqual(item._id, 'id')
예제 #8
0
    def test_class_members(self):
        doc = '''new multiline doc
            new line'''
        e = codegen.ItemEditor('tests.schema.TestItem')
        e.set_doc(doc)
        e.commit_changes()

        self.assertEqual(schema.TestItem.__doc__, doc)
        item = schema.TestItem()
        self.assertEqual(item.some_mehtod(), 'method called')
        self.assertEqual(item.p, 'getter')
예제 #9
0
    def test_multiple_inheritance(self):
        editor = codegen.ItemEditor('tests.schema.TestMultipleBasesItem')
        editor.set_property('y', datatypes.String())
        editor.commit_changes()

        item = schema.TestMultipleBasesItem()
        self.assertEqual(hasattr(item, 'x'), True)
        self.assertEqual(item.x.value, '')
        self.assertEqual(hasattr(item, 'y'), True)
        self.assertEqual(item.y.value, '')
        self.assertEqual(hasattr(item, 'z'), True)
        self.assertEqual(item.z.value, '')
        self.assertEqual(hasattr(item, 'c'), True)
        self.assertEqual(item.c.value, [])
예제 #10
0
 def test_invalid_event_handler(self):
     editor = codegen.ItemEditor('tests.schema.TestFolder')
     editor._eventHandlers.append(schema.InvalidEventHandler)
     self.assertRaises(TypeError, editor.commit_changes)