Exemplo n.º 1
0
class TiledElementTestCase(TestCase):

    def setUp(self):
        self.tiled_element = TiledElement()
        self.tiled_element.name = "Foo"

    def test_from_xml_string_should_raise_on_TiledElement(self):
        with self.assertRaises(AttributeError):
            TiledElement.from_xml_string("<element></element>")

    def test_when_property_is_reserved_contains_invalid_property_name_returns_true(self):
        self.tiled_element = TiledElement()
        self.tiled_element.name = "Foo"
        items = [("contains_invalid_property_name", None)]
        self.assertTrue(self.tiled_element.contains_invalid_property_name(items))

    def test_when_property_is_not_reserved_contains_invalid_property_name_returns_false(self):
        self.assertFalse(self.tiled_element.contains_invalid_property_name(list()))

    @patch("pytmx.parse_properties")
    def test_set_properties_raises_value_error_if_invalid_property_name_in_node(self, mock_parse_properties):
        mock_node = Mock()
        mock_node.items.return_value = list()
        self.tiled_element.contains_invalid_property_name = Mock(return_value=True)
        with self.assertRaises(ValueError):
            self.tiled_element.set_properties(mock_node)

    def test_repr(self):
        self.assertEqual("<TiledElement: \"Foo\">it add ..", self.tiled_element.__repr__())
Exemplo n.º 2
0
class TiledElementTestCase(unittest.TestCase):
    def setUp(self):
        self.element = TiledElement()

    def test_from_xml_string_should_raise_on_TiledElement(self):
        with self.assertRaises(AttributeError):
            TiledElement.from_xml_string("<element></element>")

    def test_contains_reserved_property_name(self):
        """ Reserved names are checked from any attributes in the instance
            after it is created.  Instance attributes are defaults from the
            specification.  We check that new properties are not named same
            as existing attributes.
        """
        self.element.name = 'foo'
        items = {'name': None}
        result = self.element._contains_invalid_property_name(items.items())
        self.assertTrue(result)

    def test_not_contains_reserved_property_name(self):
        """ Reserved names are checked from any attributes in the instance
            after it is created.  Instance attributes are defaults from the
            specification.  We check that new properties are not named same
            as existing attributes.
        """
        items = {'name': None}
        result = self.element._contains_invalid_property_name(items.items())
        self.assertFalse(result)

    def test_reserved_names_check_disabled_with_option(self):
        """ Reserved names are checked from any attributes in the instance
            after it is created.  Instance attributes are defaults from the
            specification.  We check that new properties are not named same
            as existing attributes.

            Check that passing an option will disable the check
        """
        pytmx.TiledElement.allow_duplicate_names = True
        self.element.name = 'foo'
        items = {'name': None}
        result = self.element._contains_invalid_property_name(items.items())
        self.assertFalse(result)

    def test_repr(self):
        self.element.name = 'foo'
        self.assertEqual("<TiledElement: \"foo\">", self.element.__repr__())
Exemplo n.º 3
0
class TiledElementTestCase(TestCase):
    def setUp(self):
        self.element = TiledElement()

    def test_from_xml_string_should_raise_on_TiledElement(self):
        with self.assertRaises(AttributeError):
            TiledElement.from_xml_string("<element></element>")

    def test_contains_reserved_property_name(self):
        """ Reserved names are checked from any attributes in the instance
            after it is created.  Instance attributes are defaults from the
            specification.  We check that new properties are not named same
            as existing attributes.
        """
        self.element.name ='foo'
        items = {'name': None}
        result = self.element._contains_invalid_property_name(items.items())
        self.assertTrue(result)

    def test_not_contains_reserved_property_name(self):
        """ Reserved names are checked from any attributes in the instance
            after it is created.  Instance attributes are defaults from the
            specification.  We check that new properties are not named same
            as existing attributes.
        """
        items = {'name': None}
        result = self.element._contains_invalid_property_name(items.items())
        self.assertFalse(result)

    def test_reserved_names_check_disabled_with_option(self):
        """ Reserved names are checked from any attributes in the instance
            after it is created.  Instance attributes are defaults from the
            specification.  We check that new properties are not named same
            as existing attributes.

            Check that passing an option will disable the check
        """
        pytmx.TiledElement.allow_duplicate_names = True
        self.element.name = 'foo'
        items = {'name': None}
        result = self.element._contains_invalid_property_name(items.items())
        self.assertFalse(result)

    def test_repr(self):
        self.element.name = 'foo'
        self.assertEqual("<TiledElement: \"foo\">", self.element.__repr__())
Exemplo n.º 4
0
 def test_from_xml_string_should_raise_on_TiledElement(self):
     with self.assertRaises(AttributeError):
         TiledElement.from_xml_string("<element></element>")
Exemplo n.º 5
0
 def setUp(self):
     self.element = TiledElement()
Exemplo n.º 6
0
 def test_from_xml_string_should_raise_on_TiledElement(self):
     with self.assertRaises(AttributeError):
         TiledElement.from_xml_string("<element></element>")
Exemplo n.º 7
0
 def setUp(self):
     self.element = TiledElement()
Exemplo n.º 8
0
 def test_when_property_is_reserved_contains_invalid_property_name_returns_true(self):
     self.tiled_element = TiledElement()
     self.tiled_element.name = "Foo"
     items = [("contains_invalid_property_name", None)]
     self.assertTrue(self.tiled_element.contains_invalid_property_name(items))
Exemplo n.º 9
0
 def setUp(self):
     self.tiled_element = TiledElement()
     self.tiled_element.name = "Foo"