Example #1
0
    def test_one_element(self):
        """elements_to_dict can handle one element."""
        elements = self.string_to_elements("""
<root>
 <ENV key="foo">bar</ENV>
</root>
""")
        self.assertEqual(elements_to_dict(elements), {"foo": "bar"})
Example #2
0
    def test_one_element(self):
        """elements_to_dict can handle one element."""
        elements = self.string_to_elements("""
<root>
 <ENV key="foo">bar</ENV>
</root>
""")
        self.assertEqual(elements_to_dict(elements), {"foo": "bar"})
Example #3
0
    def test_multiple_elements(self):
        """elements_to_dict can handle multiple elements."""
        elements = self.string_to_elements("""
<root>
 <ENV key="foo1">bar1</ENV>
 <ENV key="foo2">bar2</ENV>
</root>
""")
        self.assertEqual(elements_to_dict(elements),
                         {"foo1": "bar1", "foo2": "bar2"})
Example #4
0
    def test_key_attr(self):
        """elements_to_dict uses key_attr as key attribute."""
        key_attr = "name"
        xml_str = """
<root>
 <ENV name="foo">bar</ENV>
</root>
"""
        elements = self.string_to_elements(xml_str, ignore=key_attr)
        self.assertEqual(elements_to_dict(elements, key_attr=key_attr),
                         {"foo": "bar"})
Example #5
0
    def test_key_attr(self):
        """elements_to_dict uses key_attr as key attribute."""
        key_attr = "name"
        xml_str = """
<root>
 <ENV name="foo">bar</ENV>
</root>
"""
        elements = self.string_to_elements(xml_str, ignore=key_attr)
        self.assertEqual(elements_to_dict(elements, key_attr=key_attr),
                         {"foo": "bar"})
Example #6
0
    def test_keyless_match(self):
        """elements_to_dict with a match with no key returns empty dict.

        It might be better to raise an exception; this is a robustness and
        simplicity vs. correctness tradeoff.
        """
        elements = self.string_to_elements("""
<root>
 <ENV>bar</ENV>
</root>
""")
        self.assertEqual(elements_to_dict(elements), {})
Example #7
0
    def test_keyless_match(self):
        """elements_to_dict with a match with no key returns empty dict.

        It might be better to raise an exception; this is a robustness and
        simplicity vs. correctness tradeoff.
        """
        elements = self.string_to_elements("""
<root>
 <ENV>bar</ENV>
</root>
""")
        self.assertEqual(elements_to_dict(elements), {})
Example #8
0
    def test_multiple_elements(self):
        """elements_to_dict can handle multiple elements."""
        elements = self.string_to_elements("""
<root>
 <ENV key="foo1">bar1</ENV>
 <ENV key="foo2">bar2</ENV>
</root>
""")
        self.assertEqual(elements_to_dict(elements), {
            "foo1": "bar1",
            "foo2": "bar2"
        })
Example #9
0
    def test_multiple_key(self):
        """elements_to_dict lets later values overwrite earlier ones.

        This might not actually be the best behavior, but it's the easiest
        to implement; this test is really just to prevent *accidentally*
        changing the design.
        """
        elements = self.string_to_elements("""
<root>
 <ENV key="foo">bar1</ENV>
 <ENV key="foo">bar2</ENV>
</root>
""")
        self.assertEqual(elements_to_dict(elements), {"foo": "bar2"})
Example #10
0
    def test_multiple_key(self):
        """elements_to_dict lets later values overwrite earlier ones.

        This might not actually be the best behavior, but it's the easiest
        to implement; this test is really just to prevent *accidentally*
        changing the design.
        """
        elements = self.string_to_elements("""
<root>
 <ENV key="foo">bar1</ENV>
 <ENV key="foo">bar2</ENV>
</root>
""")
        self.assertEqual(elements_to_dict(elements),
                         {"foo": "bar2"})
Example #11
0
 def test_no_elements(self):
     """elements_to_dict with no elements produces an empty dict."""
     self.assertEqual(elements_to_dict([]), {})
Example #12
0
 def test_no_elements(self):
     """elements_to_dict with no elements produces an empty dict."""
     self.assertEqual(elements_to_dict([]), {})