From 22016ee593d6047855964734a17120d2aea6b5a5 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 21 Aug 2012 13:32:51 -0400 Subject: lots of various py3k fixes --- .../TestClient/TestTools/TestPOSIX/TestDevice.py | 12 +++---- .../TestTools/TestPOSIX/TestDirectory.py | 12 +++---- .../TestClient/TestTools/TestPOSIX/TestFile.py | 42 +++++++++++----------- .../TestClient/TestTools/TestPOSIX/TestHardlink.py | 4 +-- .../TestTools/TestPOSIX/TestNonexistent.py | 4 +-- .../TestTools/TestPOSIX/TestPermissions.py | 4 +-- .../TestClient/TestTools/TestPOSIX/TestSymlink.py | 4 +-- .../TestClient/TestTools/TestPOSIX/Testbase.py | 6 ++-- 8 files changed, 44 insertions(+), 44 deletions(-) (limited to 'testsuite/Testlib/TestClient') diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py index f32da9c37..b737cfe1e 100644 --- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py +++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDevice.py @@ -4,8 +4,8 @@ import unittest import lxml.etree from mock import Mock, MagicMock, patch from Bcfg2.Client.Tools.POSIX.Device import * -from Test__init import get_posix_object -from Testbase import TestPOSIXTool +from .Test__init import get_posix_object +from .Testbase import TestPOSIXTool from .....common import * class TestPOSIXDevice(TestPOSIXTool): @@ -97,8 +97,8 @@ class TestPOSIXDevice(TestPOSIXTool): self.assertTrue(ptool.install(entry)) mock_exists.assert_called_with(entry, remove=True) mock_makedev.assert_called_with(0, 10) - mock_mknod.assert_called_with(entry.get("name"), - device_map[entry.get("dev_type")] | 0644, + mock_mknod.assert_called_with(entry.get("name"), # 0o644 + device_map[entry.get("dev_type")] | 420, mock_makedev.return_value) mock_install.assert_called_with(ptool, entry) @@ -127,6 +127,6 @@ class TestPOSIXDevice(TestPOSIXTool): self.assertTrue(ptool.install(entry)) mock_exists.assert_called_with(entry, remove=True) - mock_mknod.assert_called_with(entry.get("name"), - device_map[entry.get("dev_type")] | 0644) + mock_mknod.assert_called_with(entry.get("name"), # 0o644 + device_map[entry.get("dev_type")] | 420) mock_install.assert_called_with(ptool, entry) diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py index 34c98fa9c..79879afed 100644 --- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py +++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestDirectory.py @@ -5,8 +5,8 @@ import unittest import lxml.etree from mock import Mock, MagicMock, patch from Bcfg2.Client.Tools.POSIX.Directory import * -from Test__init import get_posix_object -from Testbase import TestPOSIXTool +from .Test__init import get_posix_object +from .Testbase import TestPOSIXTool from .....common import * class TestPOSIXDirectory(TestPOSIXTool): @@ -25,14 +25,14 @@ class TestPOSIXDirectory(TestPOSIXTool): mock_exists.reset_mock() exists_rv = MagicMock() - exists_rv.__getitem__.return_value = stat.S_IFREG | 0644 + exists_rv.__getitem__.return_value = stat.S_IFREG | 420 # 0o644 mock_exists.return_value = exists_rv self.assertFalse(ptool.verify(entry, [])) mock_exists.assert_called_with(entry) mock_exists.reset_mock() mock_verify.return_value = False - exists_rv.__getitem__.return_value = stat.S_IFDIR | 0644 + exists_rv.__getitem__.return_value = stat.S_IFDIR | 420 # 0o644 self.assertFalse(ptool.verify(entry, [])) mock_exists.assert_called_with(entry) mock_verify.assert_called_with(ptool, entry, []) @@ -105,7 +105,7 @@ class TestPOSIXDirectory(TestPOSIXTool): reset() exists_rv = MagicMock() - exists_rv.__getitem__.return_value = stat.S_IFREG | 0644 + exists_rv.__getitem__.return_value = stat.S_IFREG | 420 # 0o644 mock_exists.return_value = exists_rv self.assertTrue(ptool.install(entry)) mock_unlink.assert_called_with(entry.get("name")) @@ -114,7 +114,7 @@ class TestPOSIXDirectory(TestPOSIXTool): mock_install.assert_called_with(ptool, entry) reset() - exists_rv.__getitem__.return_value = stat.S_IFDIR | 0644 + exists_rv.__getitem__.return_value = stat.S_IFDIR | 420 # 0o644 mock_install.return_value = True self.assertTrue(ptool.install(entry)) mock_exists.assert_called_with(entry) diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py index 06912c19c..084268959 100644 --- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py +++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestFile.py @@ -5,10 +5,11 @@ import difflib import binascii import unittest import lxml.etree +from Bcfg2.Bcfg2Py3k import b64encode, b64decode from mock import Mock, MagicMock, patch from Bcfg2.Client.Tools.POSIX.File import * -from Test__init import get_posix_object -from Testbase import TestPOSIXTool +from .Test__init import get_posix_object +from .Testbase import TestPOSIXTool from .....common import * def get_file_object(posix=None): @@ -33,17 +34,18 @@ class TestPOSIXFile(TestPOSIXTool): def test_is_string(self): ptool = self.get_obj() - for char in range(8) + range(14, 32): + for char in list(range(8)) + list(range(14, 32)): self.assertFalse(ptool._is_string("foo" + chr(char) + "bar", - 'utf_8')) - for char in range(9, 14) + range(33, 128): + 'UTF-8')) + for char in list(range(9, 14)) + list(range(33, 128)): self.assertTrue(ptool._is_string("foo" + chr(char) + "bar", - 'utf_8')) - self.assertFalse(ptool._is_string("foo" + chr(128) + "bar", - 'ascii')) + 'UTF-8')) ustr = 'é' - self.assertTrue(ptool._is_string(ustr, 'utf_8')) - self.assertFalse(ptool._is_string(ustr, 'ascii')) + self.assertTrue(ptool._is_string(ustr, 'UTF-8')) + if not inPy3k: + self.assertFalse(ptool._is_string("foo" + chr(128) + "bar", + 'ascii')) + self.assertFalse(ptool._is_string(ustr, 'ascii')) def test_get_data(self): orig_entry = lxml.etree.Element("Path", name="/test", type="file") @@ -51,7 +53,7 @@ class TestPOSIXFile(TestPOSIXTool): ptool = self.get_obj(posix=get_posix_object(setup=setup)) entry = copy.deepcopy(orig_entry) - entry.text = binascii.b2a_base64("test") + entry.text = b64encode("test") entry.set("encoding", "base64") self.assertEqual(ptool._get_data(entry), ("test", True)) @@ -63,7 +65,7 @@ class TestPOSIXFile(TestPOSIXTool): entry.text = "test" self.assertEqual(ptool._get_data(entry), ("test", False)) - ustr = u'é' + ustr = u('é') entry = copy.deepcopy(orig_entry) entry.text = ustr self.assertEqual(ptool._get_data(entry), (ustr, False)) @@ -207,7 +209,7 @@ class TestPOSIXFile(TestPOSIXTool): mock_rename.assert_called_with(newfile, entry.get("name")) mock_unlink.assert_called_with(newfile) - @patch("%.open" % builtins) + @patch("%s.open" % builtins) @patch("Bcfg2.Client.Tools.POSIX.File.%s._diff" % test_obj.__name__) @patch("Bcfg2.Client.Tools.POSIX.File.%s._get_data" % test_obj.__name__) @patch("Bcfg2.Client.Tools.POSIX.File.%s._is_string" % test_obj.__name__) @@ -239,8 +241,7 @@ class TestPOSIXFile(TestPOSIXTool): mock_open.assert_called_with(entry.get("name")) mock_open.return_value.read.assert_any_call() self.assertFalse(mock_diff.called) - self.assertEqual(entry.get("current_bfile"), - binascii.b2a_base64(ondisk)) + self.assertEqual(entry.get("current_bfile"), b64encode(ondisk)) # binary data on disk entry = reset() @@ -248,8 +249,7 @@ class TestPOSIXFile(TestPOSIXTool): ptool._get_diffs(entry, content=ondisk) self.assertFalse(mock_open.called) self.assertFalse(mock_diff.called) - self.assertEqual(entry.get("current_bfile"), - binascii.b2a_base64(ondisk)) + self.assertEqual(entry.get("current_bfile"), b64encode(ondisk)) # sensitive, non-interactive -- do nothing entry = reset() @@ -278,7 +278,7 @@ class TestPOSIXFile(TestPOSIXTool): filename=entry.get("name")) self.assertIsNone(entry.get("qtext")) self.assertEqual(entry.get("current_bdiff"), - binascii.b2a_base64("\n".join(mock_diff.return_value))) + b64encode("\n".join(mock_diff.return_value))) del entry.attrib["current_bdiff"] self.assertItemsEqual(orig_entry.attrib, entry.attrib) @@ -297,14 +297,14 @@ class TestPOSIXFile(TestPOSIXTool): self.assertIsNotNone(entry.get("qtext")) self.assertTrue(entry.get("qtext").startswith("test\n")) self.assertEqual(entry.get("current_bdiff"), - binascii.b2a_base64("\n".join(mock_diff.return_value))) + b64encode("\n".join(mock_diff.return_value))) del entry.attrib['qtext'] del entry.attrib["current_bdiff"] self.assertItemsEqual(orig_entry.attrib, entry.attrib) # non-sensitive, interactive with unicode data entry = reset() - entry.text = u"tëst" + entry.text = u("tëst") encoded = entry.text.encode(setup['encoding']) mock_get_data.return_value = (encoded, False) ptool._get_diffs(entry, interactive=True) @@ -317,7 +317,7 @@ class TestPOSIXFile(TestPOSIXTool): filename=entry.get("name"))]) self.assertIsNotNone(entry.get("qtext")) self.assertEqual(entry.get("current_bdiff"), - binascii.b2a_base64("\n".join(mock_diff.return_value))) + b64encode("\n".join(mock_diff.return_value))) del entry.attrib['qtext'] del entry.attrib["current_bdiff"] self.assertItemsEqual(orig_entry.attrib, entry.attrib) diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py index 663c98af2..221da9ea5 100644 --- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py +++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestHardlink.py @@ -4,8 +4,8 @@ import unittest import lxml.etree from mock import Mock, MagicMock, patch from Bcfg2.Client.Tools.POSIX.Hardlink import * -from Test__init import get_posix_object -from Testbase import TestPOSIXTool +from .Test__init import get_posix_object +from .Testbase import TestPOSIXTool from .....common import * class TestPOSIXHardlink(TestPOSIXTool): diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py index 8d959a15f..2b46bd9e6 100644 --- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py +++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestNonexistent.py @@ -4,8 +4,8 @@ import unittest import lxml.etree from mock import Mock, MagicMock, patch from Bcfg2.Client.Tools.POSIX.Nonexistent import * -from Test__init import get_config, get_posix_object -from Testbase import TestPOSIXTool +from .Test__init import get_config, get_posix_object +from .Testbase import TestPOSIXTool from .....common import * class TestPOSIXNonexistent(TestPOSIXTool): diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py index 9d8130658..008f0c839 100644 --- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py +++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestPermissions.py @@ -3,8 +3,8 @@ import unittest import lxml.etree from mock import Mock, MagicMock, patch from Bcfg2.Client.Tools.POSIX.Permissions import * -from Test__init import get_posix_object -from Testbase import TestPOSIXTool +from .Test__init import get_posix_object +from .Testbase import TestPOSIXTool from .....common import * class TestPOSIXPermissions(TestPOSIXTool): diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py index 03504ca61..7ce8a4437 100644 --- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py +++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/TestSymlink.py @@ -4,8 +4,8 @@ import unittest import lxml.etree from mock import Mock, MagicMock, patch from Bcfg2.Client.Tools.POSIX.Symlink import * -from Test__init import get_posix_object -from Testbase import TestPOSIXTool +from .Test__init import get_posix_object +from .Testbase import TestPOSIXTool from .....common import * class TestPOSIXSymlink(TestPOSIXTool): diff --git a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py index 442641c0b..e8e5dbe23 100644 --- a/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py +++ b/testsuite/Testlib/TestClient/TestTools/TestPOSIX/Testbase.py @@ -6,7 +6,7 @@ import lxml.etree from mock import Mock, MagicMock, patch import Bcfg2.Client.Tools from Bcfg2.Client.Tools.POSIX.base import * -from Test__init import get_posix_object +from .Test__init import get_posix_object from .....common import * try: @@ -240,13 +240,13 @@ class TestPOSIXTool(Bcfg2TestCase): raise KeyError os.chown.side_effect = chown_rv entry.set("type", "device") - entry.set("dev_type", device_map.keys()[0]) + entry.set("dev_type", list(device_map.keys())[0]) self.assertFalse(ptool._set_perms(entry)) mock_norm_uid.assert_called_with(entry) mock_norm_gid.assert_called_with(entry) mock_chown.assert_called_with(entry.get("name"), 0, 0) mock_chmod.assert_called_with(entry.get("name"), - int(entry.get("perms"), 8) | device_map.values()[0]) + int(entry.get("perms"), 8) | list(device_map.values())[0]) mock_utime.assert_called_with(entry.get("name"), (mtime, mtime)) mock_set_secontext.assert_called_with(entry, path=entry.get("name")) mock_set_acls.assert_called_with(entry, path=entry.get("name")) -- cgit v1.2.3-1-g7c22