From 84aa6558b46dd086b97234884f4185c9d5548888 Mon Sep 17 00:00:00 2001 From: Lokesh S Date: Wed, 27 Jul 2016 12:16:26 +0000 Subject: [PATCH] Py3: Make test_manager py3 compatable Fixes: NameError: name 'file' is not defined file() is removed in python3.x using open() will solve it. Fixes: AttributeError: 'generator' object has no attribute 'next' Python3 it is __next__() Change-Id: Ib2cbdfbbedb86f6e01239d2ee991677727b0548b --- test/unit/common/test_manager.py | 12 ++++++++---- tox.ini | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/unit/common/test_manager.py b/test/unit/common/test_manager.py index 17d66e0d71..865fcc3b80 100644 --- a/test/unit/common/test_manager.py +++ b/test/unit/common/test_manager.py @@ -610,14 +610,14 @@ class TestServer(unittest.TestCase): self.assertEqual(pid_file, self.join_run_dir('proxy-server.pid')) self.assertEqual(pid, 1) # ... and only one file - self.assertRaises(StopIteration, iterator.next) + self.assertRaises(StopIteration, next, iterator) # test invalid value in pid file server = manager.Server('auth', run_dir=t) pid_file, pid = next(server.iter_pid_files()) self.assertIsNone(pid) # test object-server doesn't steal pids from object-replicator server = manager.Server('object', run_dir=t) - self.assertRaises(StopIteration, server.iter_pid_files().next) + self.assertRaises(StopIteration, next, server.iter_pid_files()) # test multi-pid iter server = manager.Server('object-replicator', run_dir=t) real_map = { @@ -1129,9 +1129,13 @@ class TestServer(unittest.TestCase): self.assertEqual(len(server.procs), 3) proc = server.procs[2] # assert stdout is /dev/null - self.assertTrue(isinstance(proc.stdout, file)) + with open('/dev/null', 'wb+') as fp: + self.assertTrue(isinstance(proc.stdout, type(fp))) self.assertEqual(proc.stdout.name, os.devnull) - self.assertEqual(proc.stdout.mode, 'w+b') + self.assertIn('b', proc.stdout.mode) + self.assertTrue(any(x in proc.stdout.mode for x in 'aw+'), + 'mode must be writable, not %r' % + proc.stdout.mode) self.assertEqual(proc.stderr, proc.stdout) # test not daemon over-rides wait server.spawn(conf4, wait=False, daemon=False, once=True) diff --git a/tox.ini b/tox.ini index a3f30b67d8..582be62aa3 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,7 @@ commands = nosetests \ test/unit/common/test_exceptions.py \ test/unit/common/test_header_key_dict.py \ + test/unit/common/test_manager.py \ test/unit/common/test_splice.py [testenv:py35]