Parcourir la source

[2937] Compensate for different errors from csv

Compensate for different error message from different versions of the
csv library. We don't really care that much about which exact text of
the error is printed as long as something is printed and makes sense. So
allow both versions know to be produced.
Michal 'vorner' Vaner il y a 12 ans
Parent
commit
72fca133dd
1 fichiers modifiés avec 13 ajouts et 3 suppressions
  1. 13 3
      src/bin/usermgr/tests/b10-cmdctl-usermgr_test.py

+ 13 - 3
src/bin/usermgr/tests/b10-cmdctl-usermgr_test.py

@@ -140,6 +140,7 @@ class TestUserMgr(unittest.TestCase):
         if expected_stdout is not None:
             self.assertEqual(expected_stdout, stdout.decode())
         self.assertEqual(expected_returncode, returncode, " ".join(command))
+        return (returncode, stdout.decode(), stderr.decode())
 
     def test_help(self):
         self.run_check(0,
@@ -468,14 +469,23 @@ Options:
         # I can only think of one invalid format, an unclosed string
         with open(self.OUTPUT_FILE, 'w', newline='') as f:
             f.write('a,"\n')
-        self.run_check(2,
-                       'Using accounts file: test_users.csv\n'
-                       'Error parsing csv file: newline inside string\n',
+        # Different versions of the csv library return different errors.
+        # So we need to check the output in a little more complex way.
+        # We ask the run_check not tu check the output and check it
+        # ourselves.
+        (returncode, stdout, stderr) = self.run_check(2, None,
                        '',
                        [ self.TOOL,
                          '-f', self.OUTPUT_FILE,
                          'add', 'user1', 'pass1'
                        ])
+        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__':