aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAdam Stokes <adam.stokes@ubuntu.com>2013-10-30 22:14:55 -0400
committerAdam Stokes <adam.stokes@ubuntu.com>2013-10-30 22:14:55 -0400
commitcd99ebea74a606fe037580eead2702f4c2dd7c65 (patch)
tree3ab32f8ed6a19d2dfbfa87d8c55f86bdd0e509a7 /tests
parentc398e45ce3e22062df08c2d4f9dc1eed1ee99e1d (diff)
downloadsos-cd99ebea74a606fe037580eead2702f4c2dd7c65.tar.gz
Python 3 port
This includes a necessary dependency on python-six for its compability layer since we are wanting to continue support for both Python 2.7.x and Python 3.x. In addition, this will allow us to effectively phase out Python 2 support when/if the time arises that all interested distributions have done away with Python 2. This port passes all unittests for both python 2.7.x and python 3.3.x Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/archive_tests.py6
-rw-r--r--tests/plugin_tests.py10
-rw-r--r--tests/utilities_tests.py13
3 files changed, 20 insertions, 9 deletions
diff --git a/tests/archive_tests.py b/tests/archive_tests.py
index abdce994..9cd7bd1b 100644
--- a/tests/archive_tests.py
+++ b/tests/archive_tests.py
@@ -9,6 +9,8 @@ import shutil
from sos.archive import TarFileArchive, ZipFileArchive
+# PYCOMPAT
+import six
class ZipFileArchiveTest(unittest.TestCase):
@@ -66,14 +68,14 @@ class ZipFileArchiveTest(unittest.TestCase):
self.zf.add_string('this is my content', 'tests/string_test.txt')
afp = self.zf.open_file('tests/string_test.txt')
- self.assertEquals('this is my content', afp.read())
+ self.assertEquals(six.b('this is my content'), afp.read())
def test_overwrite_file(self):
self.zf.add_string('this is my content', 'tests/string_test.txt')
self.zf.add_string('this is my new content', 'tests/string_test.txt')
afp = self.zf.open_file('tests/string_test.txt')
- self.assertEquals('this is my new content', afp.read())
+ self.assertEquals(six.b('this is my new content'), afp.read())
# Disabled as new api doesnt provide a add_link routine
# def test_make_link(self):
diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py
index 9f8817d2..c4b540fa 100644
--- a/tests/plugin_tests.py
+++ b/tests/plugin_tests.py
@@ -1,7 +1,13 @@
import unittest
import os
import tempfile
-from StringIO import StringIO
+
+# PYCOMPAT
+import six
+if six.PY2:
+ from StringIO import StringIO
+else:
+ from io import StringIO
from sos.plugins import Plugin, regex_findall, sos_relative_path, mangle_command
from sos.archive import TarFileArchive, ZipFileArchive
@@ -14,7 +20,7 @@ def j(filename):
def create_file(size):
f = tempfile.NamedTemporaryFile(delete=False)
- f.write("*" * size * 1024 * 1024)
+ f.write(six.b("*" * size * 1024 * 1024))
f.flush()
f.close()
return f.name
diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py
index fc9e858f..3ecf8c2b 100644
--- a/tests/utilities_tests.py
+++ b/tests/utilities_tests.py
@@ -1,6 +1,9 @@
import os.path
import unittest
-from StringIO import StringIO
+
+# PYCOMPAT
+import six
+from six import StringIO
from sos.utilities import grep, DirTree, checksum, get_hash_name, is_executable, sos_get_command_output, find, tail, shell_out
import sos
@@ -32,12 +35,12 @@ class TailTest(unittest.TestCase):
def test_tail(self):
t = tail("tests/tail_test.txt", 10)
- self.assertEquals(t, "last line\n")
+ self.assertEquals(t, six.b("last line\n"))
def test_tail_too_many(self):
t = tail("tests/tail_test.txt", 200)
expected = open("tests/tail_test.txt", "r").read()
- self.assertEquals(t, expected)
+ self.assertEquals(t, six.b(expected))
class DirTreeTest(unittest.TestCase):
@@ -78,7 +81,7 @@ class ExecutableTest(unittest.TestCase):
path = os.path.join(TEST_DIR, 'test_exe.py')
ret, out, junk = sos_get_command_output(path)
self.assertEquals(ret, 0)
- self.assertEquals(out, "executed\n")
+ self.assertEquals(out, six.b("executed\n"))
def test_output_non_exe(self):
path = os.path.join(TEST_DIR, 'utility_tests.py')
@@ -88,7 +91,7 @@ class ExecutableTest(unittest.TestCase):
def test_shell_out(self):
path = os.path.join(TEST_DIR, 'test_exe.py')
- self.assertEquals("executed\n", shell_out(path))
+ self.assertEquals(six.b("executed\n"), shell_out(path))
class FindTest(unittest.TestCase):