Update other asserts that have a py2.6 unittest method

pull/9624/head
Toshio Kuratomi 10 years ago
parent c752f012f7
commit 25ac4ccef3

@ -63,12 +63,12 @@ class TestGeneralParsing(unittest.TestCase):
} }
""" """
output = load(input) output = load(input)
assert output['asdf'] == '1234' self.assertEqual(output['asdf'], '1234')
assert output['jkl'] == 5678 self.assertEqual(output['jkl'], 5678)
def parse_json_from_file(self): def parse_json_from_file(self):
output = load(MockFile(dict(a=1,b=2,c=3)),'json') output = load(MockFile(dict(a=1,b=2,c=3)),'json')
assert ouput == dict(a=1,b=2,c=3) self.assertEqual(ouput, dict(a=1,b=2,c=3))
def parse_yaml_from_dict(self): def parse_yaml_from_dict(self):
input = """ input = """
@ -76,12 +76,12 @@ class TestGeneralParsing(unittest.TestCase):
jkl: 5678 jkl: 5678
""" """
output = load(input) output = load(input)
assert output['asdf'] == '1234' self.assertEqual(output['asdf'], '1234')
assert output['jkl'] == 5678 self.assertEqual(output['jkl'], 5678)
def parse_yaml_from_file(self): def parse_yaml_from_file(self):
output = load(MockFile(dict(a=1,b=2,c=3),'yaml')) output = load(MockFile(dict(a=1,b=2,c=3),'yaml'))
assert output == dict(a=1,b=2,c=3) self.assertEqual(output, dict(a=1,b=2,c=3))
def parse_fail(self): def parse_fail(self):
input = """ input = """
@ -89,12 +89,12 @@ class TestGeneralParsing(unittest.TestCase):
*** ***
NOT VALID NOT VALID
""" """
self.failUnlessRaises(load(input), AnsibleParserError) self.assertRaises(load(input), AnsibleParserError)
def parse_fail_from_file(self): def parse_fail_from_file(self):
self.failUnlessRaises(load(MockFile(None,'fail')), AnsibleParserError) self.assertRaises(load(MockFile(None,'fail')), AnsibleParserError)
def parse_fail_invalid_type(self): def parse_fail_invalid_type(self):
self.failUnlessRaises(3000, AnsibleParsingError) self.assertRaises(3000, AnsibleParsingError)
self.failUnlessRaises(dict(a=1,b=2,c=3), AnsibleParserError) self.assertRaises(dict(a=1,b=2,c=3), AnsibleParserError)

@ -39,65 +39,65 @@ class TestModArgsDwim(unittest.TestCase):
def test_basic_shell(self): def test_basic_shell(self):
mod, args, to = self.m.parse(dict(shell='echo hi')) mod, args, to = self.m.parse(dict(shell='echo hi'))
self._debug(mod, args, to) self._debug(mod, args, to)
assert mod == 'command' self.assertEqual(mod, 'command')
assert args == dict( self.assertEqual(args, dict(
_raw_params = 'echo hi', _raw_params = 'echo hi',
_uses_shell = True, _uses_shell = True,
) ))
assert to is None assert to is None
def test_basic_command(self): def test_basic_command(self):
mod, args, to = self.m.parse(dict(command='echo hi')) mod, args, to = self.m.parse(dict(command='echo hi'))
self._debug(mod, args, to) self._debug(mod, args, to)
assert mod == 'command' self.assertEqual(mod, 'command')
assert args == dict( self.assertEqual(args, dict(
_raw_params = 'echo hi', _raw_params = 'echo hi',
) ))
assert to is None assert to is None
def test_shell_with_modifiers(self): def test_shell_with_modifiers(self):
mod, args, to = self.m.parse(dict(shell='/bin/foo creates=/tmp/baz removes=/tmp/bleep')) mod, args, to = self.m.parse(dict(shell='/bin/foo creates=/tmp/baz removes=/tmp/bleep'))
self._debug(mod, args, to) self._debug(mod, args, to)
assert mod == 'command' self.assertEqual(mod, 'command')
assert args == dict( self.assertEqual(args, dict(
creates = '/tmp/baz', creates = '/tmp/baz',
removes = '/tmp/bleep', removes = '/tmp/bleep',
_raw_params = '/bin/foo', _raw_params = '/bin/foo',
_uses_shell = True, _uses_shell = True,
) ))
assert to is None assert to is None
def test_normal_usage(self): def test_normal_usage(self):
mod, args, to = self.m.parse(dict(copy='src=a dest=b')) mod, args, to = self.m.parse(dict(copy='src=a dest=b'))
self._debug(mod, args, to) self._debug(mod, args, to)
assert mod == 'copy' self.assertEqual(mod, 'copy')
assert args == dict(src='a', dest='b') self.assertEqual(args, dict(src='a', dest='b'))
assert to is None assert to is None
def test_complex_args(self): def test_complex_args(self):
mod, args, to = self.m.parse(dict(copy=dict(src='a', dest='b'))) mod, args, to = self.m.parse(dict(copy=dict(src='a', dest='b')))
self._debug(mod, args, to) self._debug(mod, args, to)
assert mod == 'copy' self.assertEqual(mod, 'copy')
assert args == dict(src='a', dest='b') self.assertEqual(args, dict(src='a', dest='b'))
assert to is None assert to is None
def test_action_with_complex(self): def test_action_with_complex(self):
mod, args, to = self.m.parse(dict(action=dict(module='copy', src='a', dest='b'))) mod, args, to = self.m.parse(dict(action=dict(module='copy', src='a', dest='b')))
self._debug(mod, args, to) self._debug(mod, args, to)
assert mod == 'copy' self.assertEqual(mod, 'copy')
assert args == dict(src='a', dest='b') self.assertEqual(args, dict(src='a', dest='b'))
assert to is None assert to is None
def test_action_with_complex_and_complex_args(self): def test_action_with_complex_and_complex_args(self):
mod, args, to = self.m.parse(dict(action=dict(module='copy', args=dict(src='a', dest='b')))) mod, args, to = self.m.parse(dict(action=dict(module='copy', args=dict(src='a', dest='b'))))
self._debug(mod, args, to) self._debug(mod, args, to)
assert mod == 'copy' self.assertEqual(mod, 'copy')
assert args == dict(src='a', dest='b') self.assertEqual(args, dict(src='a', dest='b'))
assert to is None assert to is None
def test_local_action_string(self): def test_local_action_string(self):
mod, args, to = self.m.parse(dict(local_action='copy src=a dest=b')) mod, args, to = self.m.parse(dict(local_action='copy src=a dest=b'))
self._debug(mod, args, to) self._debug(mod, args, to)
assert mod == 'copy' self.assertEqual(mod, 'copy')
assert args == dict(src='a', dest='b') self.assertEqual(args, dict(src='a', dest='b'))
assert to is 'localhost' assert to is 'localhost'

@ -74,23 +74,23 @@ class TestSafeLoad(unittest.TestCase):
def test_safe_load(self): def test_safe_load(self):
# test basic dictionary # test basic dictionary
res = safe_load(data1) res = safe_load(data1)
assert type(res) == AnsibleMapping self.assertEqual(type(res), AnsibleMapping)
assert res._line_number == 2 self.assertEqual(res._line_number, 2)
# test data with multiple dictionaries # test data with multiple dictionaries
res = safe_load(data2) res = safe_load(data2)
assert len(res) == 4 self.assertEqual(len(res), 4)
assert res[0]._line_number == 2 self.assertEqual(res[0]._line_number, 2)
assert res[1]._line_number == 3 self.assertEqual(res[1]._line_number, 3)
assert res[2]._line_number == 5 self.assertEqual(res[2]._line_number, 5)
assert res[3]._line_number == 8 self.assertEqual(res[3]._line_number, 8)
# test data with multiple sub-dictionaries # test data with multiple sub-dictionaries
res = safe_load(data3) res = safe_load(data3)
assert len(res) == 3 self.assertEqual(len(res), 3)
assert res[0]._line_number == 2 self.assertEqual(res[0]._line_number, 2)
assert res[1]._line_number == 7 self.assertEqual(res[1]._line_number, 7)
assert res[2]._line_number == 9 self.assertEqual(res[2]._line_number, 9)
assert res[0]['key1']._line_number == 3 self.assertEqual(res[0]['key1']._line_number, 3)
assert res[1]['key2']._line_number == 8 self.assertEqual(res[1]['key2']._line_number, 8)
assert res[2]['list1'][0]._line_number == 10 self.assertEqual(res[2]['list1'][0]._line_number, 10)

Loading…
Cancel
Save