Skip to content

Commit c6ddf09

Browse files
committed
Made tests Python 3 compliant
1 parent a121f88 commit c6ddf09

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

smartdispatch/tests/test_smartdispatch.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import shutil
44
import time as t
55
from os.path import join as pjoin
6-
7-
try:
8-
from io import StringIO # Python 3
9-
except ImportError:
10-
from StringIO import StringIO # Python 2
6+
from io import StringIO, open
117

128
import tempfile
139
from nose.tools import assert_true, assert_equal
@@ -47,11 +43,11 @@ def test_get_commands_from_file():
4743
commands = ["command1 arg1 arg2",
4844
"command2",
4945
"command3 arg1 arg2 arg3 arg4"]
50-
fileobj = StringIO("\n".join(commands))
46+
fileobj = StringIO(u"\n".join(commands))
5147
assert_array_equal(smartdispatch.get_commands_from_file(fileobj), commands)
5248

5349
# Test stripping last line if empty
54-
fileobj = StringIO("\n".join(commands) + "\n")
50+
fileobj = StringIO(u"\n".join(commands) + u"\n")
5551
assert_array_equal(smartdispatch.get_commands_from_file(fileobj), commands)
5652

5753

smartdispatch/tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_open_with_lock():
7575

7676
stdout, stderr = process.communicate()
7777
assert_equal(stdout, b"")
78-
assert_true("write-lock" in stderr, msg="Forcing a race condition, try increasing sleeping time above.")
79-
assert_true("Traceback" not in stderr, msg="Unexpected error: " + stderr) # Check that there are no errors.
78+
assert_true("write-lock" in stderr.decode(), msg="Forcing a race condition, try increasing sleeping time above.")
79+
assert_true("Traceback" not in stderr.decode(), msg="Unexpected error: " + stderr.decode()) # Check that there are no errors.
8080

8181
shutil.rmtree(temp_dir)

tests/test_smart_worker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def setUp(self):
2222
self.command_manager = CommandManager(os.path.join(self._commands_dir, "commands.txt"))
2323
self.command_manager.set_commands_to_run(self.commands)
2424

25-
self.commands_uid = map(utils.generate_uid_from_string, self.commands)
25+
self.commands_uid = list(map(utils.generate_uid_from_string, self.commands))
2626

2727
def tearDown(self):
2828
shutil.rmtree(self._commands_dir)
@@ -111,6 +111,6 @@ def test_lock(self):
111111
time.sleep(1)
112112

113113
stdout, stderr = process.communicate()
114-
assert_equal(stdout, "")
115-
assert_true("write-lock" in stderr, msg="Forcing a race condition, try increasing sleeping time above.")
116-
assert_true("Traceback" not in stderr) # Check that there are no errors.
114+
assert_equal(stdout, b"")
115+
assert_true("write-lock" in stderr.decode(), msg="Forcing a race condition, try increasing sleeping time above.")
116+
assert_true("Traceback" not in stderr.decode()) # Check that there are no errors.

0 commit comments

Comments
 (0)