Commit 8c114acd authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

test/*.py: s/'/"/



Now that 2.6 is essentially finished and 2.7 going to be branched
soon-ish, I thought it would be a good moment to replace some single
quotes in test/*.py. Merge pains should be limited.

In one place in test/ganeti.locking_unittest.py, spaces are added for
assignments.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 5b34cc22
......@@ -312,7 +312,7 @@ class TestDRBD8Status(testutils.GanetiTestCase):
stats = bdev.DRBD8Status(data[4])
self.failUnless(stats.is_in_use)
self.failUnless(stats.is_wfconn and stats.is_primary and
stats.rrole == 'Unknown' and
stats.rrole == "Unknown" and
stats.is_disk_uptodate)
def testMinor6(self):
......@@ -329,7 +329,7 @@ class TestDRBD8Status(testutils.GanetiTestCase):
stats = bdev.DRBD8Status(data[8])
self.failUnless(stats.is_in_use)
self.failUnless(stats.is_standalone and
stats.rrole == 'Unknown' and
stats.rrole == "Unknown" and
stats.is_disk_uptodate)
def testDRBD83SyncFine(self):
......
......@@ -43,14 +43,14 @@ class TestParseTimespec(unittest.TestCase):
def testValidTimes(self):
"""Test valid timespecs"""
test_data = [
('1s', 1),
('1', 1),
('1m', 60),
('1h', 60 * 60),
('1d', 60 * 60 * 24),
('1w', 60 * 60 * 24 * 7),
('4h', 4 * 60 * 60),
('61m', 61 * 60),
("1s", 1),
("1", 1),
("1m", 60),
("1h", 60 * 60),
("1d", 60 * 60 * 24),
("1w", 60 * 60 * 24 * 7),
("4h", 4 * 60 * 60),
("61m", 61 * 60),
]
for value, expected_result in test_data:
self.failUnlessEqual(cli.ParseTimespec(value), expected_result)
......@@ -58,10 +58,10 @@ class TestParseTimespec(unittest.TestCase):
def testInvalidTime(self):
"""Test invalid timespecs"""
test_data = [
'1y',
'',
'aaa',
's',
"1y",
"",
"aaa",
"s",
]
for value in test_data:
self.failUnlessRaises(OpPrereqError, cli.ParseTimespec, value)
......@@ -128,7 +128,7 @@ class TestToStream(unittest.TestCase):
]:
buf = StringIO()
cli._ToStream(buf, data)
self.failUnlessEqual(buf.getvalue(), data+'\n')
self.failUnlessEqual(buf.getvalue(), data + "\n")
def testParams(self):
buf = StringIO()
......
......@@ -183,14 +183,14 @@ class TestConfigRunner(unittest.TestCase):
CheckSyntax = objects.NIC.CheckParameterSyntax
CheckSyntax(constants.NICC_DEFAULTS)
CheckSyntax({mode: m_bridged, link: 'br1'})
CheckSyntax({mode: m_routed, link: 'default'})
CheckSyntax({mode: m_bridged, link: "br1"})
CheckSyntax({mode: m_routed, link: "default"})
self.assertRaises(errors.ConfigurationError,
CheckSyntax, {mode: '000invalid', link: 'any'})
CheckSyntax, {mode: "000invalid", link: "any"})
self.assertRaises(errors.ConfigurationError,
CheckSyntax, {mode: m_bridged, link: None})
self.assertRaises(errors.ConfigurationError,
CheckSyntax, {mode: m_bridged, link: ''})
CheckSyntax, {mode: m_bridged, link: ""})
def testGetNdParamsDefault(self):
cfg = self._get_object()
......
......@@ -115,9 +115,9 @@ class TestParameterNames(unittest.TestCase):
VALID_NAME = re.compile("^[a-zA-Z_][a-zA-Z0-9_]*$")
def testNoDashes(self):
for kind, source in [('hypervisor', constants.HVS_PARAMETER_TYPES),
('backend', constants.BES_PARAMETER_TYPES),
('nic', constants.NICS_PARAMETER_TYPES),
for kind, source in [("hypervisor", constants.HVS_PARAMETER_TYPES),
("backend", constants.BES_PARAMETER_TYPES),
("nic", constants.NICS_PARAMETER_TYPES),
("instdisk", constants.IDISK_PARAMS_TYPES),
("instnic", constants.INIC_PARAMS_TYPES),
]:
......
......@@ -206,7 +206,7 @@ def FakeHooksRpcSuccess(node_list, hpath, phase, env):
"""
rr = rpc.RpcResult
return dict([(node, rr((True, [("utest", constants.HKR_SUCCESS, "ok")]),
node=node, call='FakeScriptOk'))
node=node, call="FakeScriptOk"))
for node in node_list])
......@@ -225,8 +225,8 @@ class TestHooksMaster(unittest.TestCase):
@return: rpc failure from all nodes
"""
return dict([(node, rpc.RpcResult('error', failed=True,
node=node, call='FakeError')) for node in node_list])
return dict([(node, rpc.RpcResult("error", failed=True,
node=node, call="FakeError")) for node in node_list])
@staticmethod
def _call_script_fail(node_list, hpath, phase, env):
......@@ -238,7 +238,7 @@ class TestHooksMaster(unittest.TestCase):
"""
rr = rpc.RpcResult
return dict([(node, rr((True, [("utest", constants.HKR_FAIL, "err")]),
node=node, call='FakeScriptFail'))
node=node, call="FakeScriptFail"))
for node in node_list])
def setUp(self):
......
This diff is collapsed.
......@@ -32,22 +32,22 @@ import testutils
class SimpleObject(objects.ConfigObject):
__slots__ = ['a', 'b']
__slots__ = ["a", "b"]
class TestDictState(unittest.TestCase):
"""Simple dict tansformation tests"""
def testSimpleObjectToDict(self):
o1 = SimpleObject(a='1')
self.assertEquals(o1.ToDict(), {'a': '1'})
self.assertEquals(o1.__getstate__(), {'a': '1'})
o1 = SimpleObject(a="1")
self.assertEquals(o1.ToDict(), {"a": "1"})
self.assertEquals(o1.__getstate__(), {"a": "1"})
self.assertEquals(o1.__getstate__(), o1.ToDict())
o1.a = 2
o1.b = 5
self.assertEquals(o1.ToDict(), {'a': 2, 'b': 5})
self.assertEquals(o1.ToDict(), {"a": 2, "b": 5})
o2 = SimpleObject.FromDict(o1.ToDict())
self.assertEquals(o1.ToDict(), {'a': 2, 'b': 5})
self.assertEquals(o1.ToDict(), {"a": 2, "b": 5})
class TestClusterObject(unittest.TestCase):
......
......@@ -220,16 +220,16 @@ EXP_PARTIAL_GANETI_DICT = {
"version": "0",
}
EXP_GANETI_DICT = {
'tags': None,
'auto_balance': 'False',
'hypervisor': {
'root-path': '/dev/sda',
'name': 'xen-pvm',
'kernel_args': 'ro'
"tags": None,
"auto_balance": "False",
"hypervisor": {
"root-path": "/dev/sda",
"name": "xen-pvm",
"kernel_args": "ro"
},
'version': '0',
'disk_template': None,
'os': {'name': 'lenny-image'}
"version": "0",
"disk_template": None,
"os": {"name": "lenny-image"}
}
EXP_NAME ="xen-dev-i1"
EXP_VCPUS = 1
......
......@@ -53,16 +53,16 @@ class MapperTests(unittest.TestCase):
self._TestFailingUri("/instances")
self._TestUri("/version", (rlib2.R_version, [], {}))
self._TestUri('/2/instances/www.test.com',
self._TestUri("/2/instances/www.test.com",
(rlib2.R_2_instances_name,
['www.test.com'],
["www.test.com"],
{}))
self._TestUri('/2/instances/www.test.com/tags?f=5&f=6&alt=html',
self._TestUri("/2/instances/www.test.com/tags?f=5&f=6&alt=html",
(rlib2.R_2_instances_name_tags,
['www.test.com'],
{'alt': ['html'],
'f': ['5', '6'],
["www.test.com"],
{"alt": ["html"],
"f": ["5", "6"],
}))
self._TestFailingUri("/tag")
......
......@@ -71,7 +71,7 @@ class TestSerializer(testutils.GanetiTestCase):
def _TestSigned(self, dump_fn, load_fn):
for data in self._TESTDATA:
self.assertEqualValues(load_fn(dump_fn(data, "mykey"), "mykey"),
(data, ''))
(data, ""))
self.assertEqualValues(load_fn(dump_fn(data, "myprivatekey",
salt="mysalt"),
"myprivatekey"),
......
......@@ -470,8 +470,8 @@ class TestRemoveFile(unittest.TestCase):
def setUp(self):
"""Create a temp dir and file for each case"""
self.tmpdir = tempfile.mkdtemp('', 'ganeti-unittest-')
fd, self.tmpfile = tempfile.mkstemp('', '', self.tmpdir)
self.tmpdir = tempfile.mkdtemp("", "ganeti-unittest-")
fd, self.tmpfile = tempfile.mkstemp("", "", self.tmpdir)
os.close(fd)
def tearDown(self):
......@@ -772,15 +772,15 @@ class TestPidFileFunctions(unittest.TestCase):
self.f_dpn = lambda name: os.path.join(self.dir, "%s.pid" % name)
def testPidFileFunctions(self):
pid_file = self.f_dpn('test')
fd = utils.WritePidFile(self.f_dpn('test'))
pid_file = self.f_dpn("test")
fd = utils.WritePidFile(self.f_dpn("test"))
self.failUnless(os.path.exists(pid_file),
"PID file should have been created")
read_pid = utils.ReadPidFile(pid_file)
self.failUnlessEqual(read_pid, os.getpid())
self.failUnless(utils.IsProcessAlive(read_pid))
self.failUnlessRaises(errors.PidFileLockError, utils.WritePidFile,
self.f_dpn('test'))
self.f_dpn("test"))
os.close(fd)
utils.RemoveFile(self.f_dpn("test"))
self.failIf(os.path.exists(pid_file),
......@@ -793,19 +793,19 @@ class TestPidFileFunctions(unittest.TestCase):
self.failUnlessEqual(utils.ReadPidFile(pid_file), 0,
"ReadPidFile should return 0 for invalid pid file")
# but now, even with the file existing, we should be able to lock it
fd = utils.WritePidFile(self.f_dpn('test'))
fd = utils.WritePidFile(self.f_dpn("test"))
os.close(fd)
utils.RemoveFile(self.f_dpn("test"))
self.failIf(os.path.exists(pid_file),
"PID file should not exist anymore")
def testKill(self):
pid_file = self.f_dpn('child')
pid_file = self.f_dpn("child")
r_fd, w_fd = os.pipe()
new_pid = os.fork()
if new_pid == 0: #child
utils.WritePidFile(self.f_dpn('child'))
os.write(w_fd, 'a')
utils.WritePidFile(self.f_dpn("child"))
os.write(w_fd, "a")
signal.pause()
os._exit(0)
return
......@@ -829,7 +829,7 @@ class TestPidFileFunctions(unittest.TestCase):
utils.KillProcess(new_pid, waitpid=True)
self.failIf(utils.IsProcessAlive(new_pid))
utils.RemoveFile(self.f_dpn('child'))
utils.RemoveFile(self.f_dpn("child"))
self.failUnlessRaises(errors.ProgrammerError, utils.KillProcess, 0)
def testExceptionType(self):
......@@ -844,14 +844,14 @@ class TestPidFileFunctions(unittest.TestCase):
class TestSshKeys(testutils.GanetiTestCase):
"""Test case for the AddAuthorizedKey function"""
KEY_A = 'ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a'
KEY_A = "ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a"
KEY_B = ('command="/usr/bin/fooserver -t --verbose",from="198.51.100.4" '
'ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b')
"ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b")
def setUp(self):
testutils.GanetiTestCase.setUp(self)
self.tmpname = self._CreateTempFile()
handle = open(self.tmpname, 'w')
handle = open(self.tmpname, "w")
try:
handle.write("%s\n" % TestSshKeys.KEY_A)
handle.write("%s\n" % TestSshKeys.KEY_B)
......@@ -860,7 +860,7 @@ class TestSshKeys(testutils.GanetiTestCase):
def testAddingNewKey(self):
utils.AddAuthorizedKey(self.tmpname,
'ssh-dss AAAAB3NzaC1kc3MAAACB root@test')
"ssh-dss AAAAB3NzaC1kc3MAAACB root@test")
self.assertFileContent(self.tmpname,
"ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a\n"
......@@ -870,7 +870,7 @@ class TestSshKeys(testutils.GanetiTestCase):
def testAddingAlmostButNotCompletelyTheSameKey(self):
utils.AddAuthorizedKey(self.tmpname,
'ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@test')
"ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@test")
# Only significant fields are compared, therefore the key won't be
# updated/added
......@@ -893,7 +893,7 @@ class TestSshKeys(testutils.GanetiTestCase):
def testRemovingExistingKeyWithSomeMoreSpaces(self):
utils.RemoveAuthorizedKey(self.tmpname,
'ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a')
"ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a")
self.assertFileContent(self.tmpname,
'command="/usr/bin/fooserver -t --verbose",from="198.51.100.4"'
......@@ -901,7 +901,7 @@ class TestSshKeys(testutils.GanetiTestCase):
def testRemovingNonExistingKey(self):
utils.RemoveAuthorizedKey(self.tmpname,
'ssh-dss AAAAB3Nsdfj230xxjxJjsjwjsjdjU root@test')
"ssh-dss AAAAB3Nsdfj230xxjxJjsjwjsjdjU root@test")
self.assertFileContent(self.tmpname,
"ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a\n"
......
......@@ -261,14 +261,14 @@ class TestShellQuoting(unittest.TestCase):
"""Test case for shell quoting functions"""
def testShellQuote(self):
self.assertEqual(utils.ShellQuote('abc'), "abc")
self.assertEqual(utils.ShellQuote("abc"), "abc")
self.assertEqual(utils.ShellQuote('ab"c'), "'ab\"c'")
self.assertEqual(utils.ShellQuote("a'bc"), "'a'\\''bc'")
self.assertEqual(utils.ShellQuote("a b c"), "'a b c'")
self.assertEqual(utils.ShellQuote("a b\\ c"), "'a b\\ c'")
def testShellQuoteArgs(self):
self.assertEqual(utils.ShellQuoteArgs(['a', 'b', 'c']), "a b c")
self.assertEqual(utils.ShellQuoteArgs(["a", "b", "c"]), "a b c")
self.assertEqual(utils.ShellQuoteArgs(['a', 'b"', 'c']), "a 'b\"' c")
self.assertEqual(utils.ShellQuoteArgs(['a', 'b\'', 'c']), "a 'b'\\\''' c")
......
......@@ -180,29 +180,29 @@ class TestForceDictType(unittest.TestCase):
def testSimpleDict(self):
self.assertEqual(self._fdt({}), {})
self.assertEqual(self._fdt({'a': 1}), {'a': 1})
self.assertEqual(self._fdt({'a': '1'}), {'a': 1})
self.assertEqual(self._fdt({'a': 1, 'b': 1}), {'a':1, 'b': True})
self.assertEqual(self._fdt({'b': 1, 'c': 'foo'}), {'b': True, 'c': 'foo'})
self.assertEqual(self._fdt({'b': 1, 'c': False}), {'b': True, 'c': ''})
self.assertEqual(self._fdt({'b': 'false'}), {'b': False})
self.assertEqual(self._fdt({'b': 'False'}), {'b': False})
self.assertEqual(self._fdt({'b': False}), {'b': False})
self.assertEqual(self._fdt({'b': 'true'}), {'b': True})
self.assertEqual(self._fdt({'b': 'True'}), {'b': True})
self.assertEqual(self._fdt({'d': '4'}), {'d': 4})
self.assertEqual(self._fdt({'d': '4M'}), {'d': 4})
self.assertEqual(self._fdt({"a": 1}), {"a": 1})
self.assertEqual(self._fdt({"a": "1"}), {"a": 1})
self.assertEqual(self._fdt({"a": 1, "b": 1}), {"a":1, "b": True})
self.assertEqual(self._fdt({"b": 1, "c": "foo"}), {"b": True, "c": "foo"})
self.assertEqual(self._fdt({"b": 1, "c": False}), {"b": True, "c": ""})
self.assertEqual(self._fdt({"b": "false"}), {"b": False})
self.assertEqual(self._fdt({"b": "False"}), {"b": False})
self.assertEqual(self._fdt({"b": False}), {"b": False})
self.assertEqual(self._fdt({"b": "true"}), {"b": True})
self.assertEqual(self._fdt({"b": "True"}), {"b": True})
self.assertEqual(self._fdt({"d": "4"}), {"d": 4})
self.assertEqual(self._fdt({"d": "4M"}), {"d": 4})
self.assertEqual(self._fdt({"e": None, }), {"e": None, })
self.assertEqual(self._fdt({"e": "Hello World", }), {"e": "Hello World", })
self.assertEqual(self._fdt({"e": False, }), {"e": '', })
self.assertEqual(self._fdt({"e": False, }), {"e": "", })
self.assertEqual(self._fdt({"b": "hello", }, ["hello"]), {"b": "hello"})
def testErrors(self):
self.assertRaises(errors.TypeEnforcementError, self._fdt, {'a': 'astring'})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {"a": "astring"})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {"b": "hello"})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {'c': True})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {'d': 'astring'})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {'d': '4 L'})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {"c": True})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {"d": "astring"})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {"d": "4 L"})
self.assertRaises(errors.TypeEnforcementError, self._fdt, {"e": object(), })
self.assertRaises(errors.TypeEnforcementError, self._fdt, {"e": [], })
self.assertRaises(errors.TypeEnforcementError, self._fdt, {"x": None, })
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment