diff options
| author | Stefan Behnel <stefan_ml@behnel.de> | 2019-03-26 15:06:07 +0100 |
|---|---|---|
| committer | Stefan Behnel <stefan_ml@behnel.de> | 2019-03-26 15:06:07 +0100 |
| commit | 2192ef03508f16fe3b0805dfe7db74706f348bc2 (patch) | |
| tree | ec06483b617da49e14fab7d589b5c891a0657a9f /src | |
| parent | eaf494a41a427b0e2fffaa83e2de75d7b9e21856 (diff) | |
| download | python-lxml-2192ef03508f16fe3b0805dfe7db74706f348bc2.tar.gz | |
Clean up test file.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lxml/tests/test_io.py | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/lxml/tests/test_io.py b/src/lxml/tests/test_io.py index 33e59010..21682c5e 100644 --- a/src/lxml/tests/test_io.py +++ b/src/lxml/tests/test_io.py @@ -5,15 +5,13 @@ IO test cases that apply to both etree and ElementTree """ import unittest -import tempfile, gzip, os, os.path, sys, gc, shutil +import tempfile, gzip, os, os.path, gc, shutil -this_dir = os.path.dirname(__file__) -if this_dir not in sys.path: - sys.path.insert(0, this_dir) # needed for Py3 - -from common_imports import etree, ElementTree, _str, _bytes -from common_imports import SillyFileLike, LargeFileLike, HelperTestCase -from common_imports import read_file, write_to_file, BytesIO +from lxml.tests.common_imports import ( + etree, ElementTree, _str, _bytes, + SillyFileLike, LargeFileLike, HelperTestCase, + read_file, write_to_file, BytesIO +) class _IOTestCaseBase(HelperTestCase): @@ -28,7 +26,7 @@ class _IOTestCaseBase(HelperTestCase): self.root_str = self.etree.tostring(self.root) self.tree = self.etree.ElementTree(self.root) self._temp_dir = tempfile.mkdtemp() - + def tearDown(self): gc.collect() shutil.rmtree(self._temp_dir) @@ -38,7 +36,7 @@ class _IOTestCaseBase(HelperTestCase): def buildNodes(self, element, children, depth): Element = self.etree.Element - + if depth == 0: return for i in range(children): @@ -49,7 +47,7 @@ class _IOTestCaseBase(HelperTestCase): def test_tree_io(self): Element = self.etree.Element ElementTree = self.etree.ElementTree - + element = Element('top') element.text = _str("qwrtioüöä\uAABB") tree = ElementTree(element) @@ -95,10 +93,10 @@ class _IOTestCaseBase(HelperTestCase): data2 = f.read() f.close() self.assertEqual(data1, data2) - + def test_write_filename(self): # (c)ElementTree supports filename strings as write argument - + handle, filename = tempfile.mkstemp(suffix=".xml") self.tree.write(filename) try: @@ -107,7 +105,7 @@ class _IOTestCaseBase(HelperTestCase): finally: os.close(handle) os.remove(filename) - + def test_write_invalid_filename(self): filename = os.path.join( os.path.join('hopefullynonexistingpathname'), @@ -140,7 +138,7 @@ class _IOTestCaseBase(HelperTestCase): # the root of the tree # parse from filename - + handle, filename = tempfile.mkstemp(suffix=".xml") write_to_file(filename, self.root_str, 'wb') try: @@ -171,13 +169,13 @@ class _IOTestCaseBase(HelperTestCase): finally: os.close(handle) os.remove(filename) - + def test_class_parse_fileobject(self): # (c)ElementTree class ElementTree has a 'parse' method that returns # the root of the tree # parse from file object - + handle, filename = tempfile.mkstemp(suffix=".xml") try: os.write(handle, self.root_str) |
