Ejemplo n.º 1
0
 def _test_string(self, xml):
     source = ETSource(xml)
     with source as src:
         assert_equals(src.read().decode('UTF-8'), xml)
     self._verify_string_representation(source, '<in-memory file>')
     assert_true(source._opened.closed)
     with ETSource(xml) as src:
         assert_equals(ET.parse(src).getroot().tag, 'tag')
Ejemplo n.º 2
0
 def _test_string(self, xml, encoding='UTF-8'):
     source = ETSource(xml)
     with source as src:
         content = src.read()
         expected = xml if isinstance(xml, bytes) else xml.encode(encoding)
         assert_equal(content, expected)
     self._verify_string_representation(source, '<in-memory file>')
     assert_true(source._opened.closed)
     with ETSource(xml) as src:
         assert_equal(ET.parse(src).getroot().tag, 'tag')
Ejemplo n.º 3
0
 def _test_string(self, xml):
     source = ETSource(xml)
     with source as src:
         content = src.read()
         if not IRONPYTHON_WITH_BROKEN_ETREE:
             content = content.decode('UTF-8')
         assert_equal(content, xml)
     self._verify_string_representation(source, '<in-memory file>')
     assert_true(source._opened.closed)
     with ETSource(xml) as src:
         assert_equal(ET.parse(src).getroot().tag, 'tag')
Ejemplo n.º 4
0
 def test_opened_file_object(self):
     source = ETSource(open(PATH))
     with source as src:
         assert_true(src.read().startswith(STARTSWITH))
     assert_true(src.closed is False)
     self._verify_string_representation(source, PATH)
     assert_true(source._opened is None)
Ejemplo n.º 5
0
 def test_xml_string(self):
     xml = '<tag>content</tag>'
     source = ETSource(xml)
     with source as src:
         assert_equals(src.read(), xml)
     self._verify_string_representation(source, '<in-memory file>')
     assert_true(source._opened.closed)
Ejemplo n.º 6
0
 def test_opened_file_object(self):
     with open(PATH) as f:
         source = ETSource(f)
         with source as src:
             assert_true(src.read().startswith('import os'))
             assert_true(src is f)
         assert_true(src.closed is False)
         self._verify_string_representation(source, PATH)
         assert_true(source._opened is None)
         assert_true(src is f)
     assert_true(src.closed is True)
Ejemplo n.º 7
0
 def test_path_to_file(self):
     source = ETSource(PATH)
     with source as src:
         if IRONPYTHON:
             assert_equals(src, PATH)
         else:
             assert_true(src.read().startswith(STARTSWITH.encode()))
     self._verify_string_representation(source, PATH)
     if IRONPYTHON:
         assert_true(source._opened is None)
     else:
         assert_true(source._opened.closed)
Ejemplo n.º 8
0
 def test_non_ascii_string_repr(self):
     self._verify_string_representation(ETSource(u'\xe4'), u'\xe4')
Ejemplo n.º 9
0
    def test_path_is_validated(self):
        def use(src):
            with src:
                pass

        assert_raises(IOError, use, ETSource('nonex.xml'))
Ejemplo n.º 10
0
 def test_path_to_file(self):
     source = ETSource(PATH)
     with source as src:
         assert_equals(src, PATH)
     self._verify_string_representation(source, PATH)
     assert_true(source._opened is None)
Ejemplo n.º 11
0
 def _test_path(self, path, string_repr=None, expected=None):
     source = ETSource(path)
     with source as src:
         assert_equal(src, expected or path)
     self._verify_string_representation(source, string_repr or path)
     assert_true(source._opened is None)