Commit 6f344e77 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

Merge #2937

Fix CSV-related test for usermanager that failed on some versions of
python (seen on 3.2.4 on Gentoo).
parents 2500db66 c8d00f7c
...@@ -75,7 +75,7 @@ class UserManager: ...@@ -75,7 +75,7 @@ class UserManager:
# Just let any file read error bubble up; it will # Just let any file read error bubble up; it will
# be caught in the run() method # be caught in the run() method
with open(self.options.output_file, newline='') as csvfile: with open(self.options.output_file, newline='') as csvfile:
reader = csv.reader(csvfile) reader = csv.reader(csvfile, strict=True)
for row in reader: for row in reader:
self.user_info[row[0]] = row self.user_info[row[0]] = row
......
...@@ -133,6 +133,8 @@ class TestUserMgr(unittest.TestCase): ...@@ -133,6 +133,8 @@ class TestUserMgr(unittest.TestCase):
May be None, in which case the check is skipped. May be None, in which case the check is skipped.
expected_stderr, (multiline) string that is checked against stderr. expected_stderr, (multiline) string that is checked against stderr.
May be None, in which case the check is skipped. May be None, in which case the check is skipped.
Returns the standard output and error captured to a string.
""" """
(returncode, stdout, stderr) = run(command) (returncode, stdout, stderr) = run(command)
if expected_stderr is not None: if expected_stderr is not None:
...@@ -140,6 +142,7 @@ class TestUserMgr(unittest.TestCase): ...@@ -140,6 +142,7 @@ class TestUserMgr(unittest.TestCase):
if expected_stdout is not None: if expected_stdout is not None:
self.assertEqual(expected_stdout, stdout.decode()) self.assertEqual(expected_stdout, stdout.decode())
self.assertEqual(expected_returncode, returncode, " ".join(command)) self.assertEqual(expected_returncode, returncode, " ".join(command))
return (stdout.decode(), stderr.decode())
def test_help(self): def test_help(self):
self.run_check(0, self.run_check(0,
...@@ -468,14 +471,26 @@ Options: ...@@ -468,14 +471,26 @@ Options:
# I can only think of one invalid format, an unclosed string # I can only think of one invalid format, an unclosed string
with open(self.OUTPUT_FILE, 'w', newline='') as f: with open(self.OUTPUT_FILE, 'w', newline='') as f:
f.write('a,"\n') f.write('a,"\n')
self.run_check(2, # Different versions of the csv library return different errors.
'Using accounts file: test_users.csv\n' # So we need to check the output in a little more complex way.
'Error parsing csv file: newline inside string\n', # We ask the run_check not to check the output and check it
# ourselves.
(stdout, stderr) = self.run_check(2, None,
'', '',
[ self.TOOL, [ self.TOOL,
'-f', self.OUTPUT_FILE, '-f', self.OUTPUT_FILE,
'add', 'user1', 'pass1' 'add', 'user1', 'pass1'
]) ])
# This looks little bit awkward, but is probably easiest with
# just 2 known possibilities. If there are more, we'll have to
# think of something else.
self.assertTrue(stdout ==
'Using accounts file: test_users.csv\n'
'Error parsing csv file: newline inside string\n' or
stdout ==
'Using accounts file: test_users.csv\n'
'Error parsing csv file: unexpected end of data\n')
if __name__== '__main__': if __name__== '__main__':
......
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