def test_shell(self): """ Test interactive shell """ with mock.patch("sys.stdin", StringIO("PRG\n\nBLT,AO\nEPG")): with self.assertRaises(SystemExit) as cm: main(["shell", "-n"]) self.assertEqual(cm.exception.code, None) with mock.patch("sys.stdin", PseudoTTY(StringIO("PRG\n\nBLT,AO\nEPG"))): with self.assertRaises(SystemExit) as cm: main(["shell", "-n"]) self.assertEqual(cm.exception.code, None)
def test_import(self): """ Normal import into bank 1. """ with mock.patch("os.path.isfile", return_value=True): with mock.patch.object(builtins, 'open', return_value=StringIO(IMPORT)): main(["import", "-n", "-b", "1", "-i", "import.csv"])
def test_import_nofile(self): """ Non-existing file import. """ with mock.patch("os.path.isfile", return_value=False): with self.assertRaises(SystemExit) as cm: main(["import", "-n", "-i", "doesnotexist.csv"]) self.assertNotEqual(cm.exception.code, None)
def test_verify_nofile(self): """ Verify csv data from non-existing file. """ with mock.patch("os.path.isfile", return_value=False): with self.assertRaises(SystemExit) as cm: main(["verify", "-v", "-i", "doesnotexist.csv"]) self.assertStdErr("") self.assertNotEqual(cm.exception.code, None)
def test_import_errors(self): """ Invalid import into bank 2. """ with mock.patch("os.path.isfile", return_value=True): with mock.patch.object(builtins, 'open', return_value=StringIO(IMPORT_ERRORS)): with self.assertRaises(SystemExit) as cm: main(["import", "-n", "-b", "2", "-i", "import_errors.csv"]) self.assertNotEqual(cm.exception.code, None)
def test_verify_stdin(self): """ Verify csv data from stdin. """ with mock.patch("sys.stdin", StringIO(IMPORT)): with self.assertRaises(SystemExit) as cm: main(["verify"]) self.assertStdOut("") self.assertStdErr("") self.assertEqual(cm.exception.code, None)
def test_verify_file(self): """ Verify csv data from file. """ with mock.patch("os.path.isfile", return_value=True): with mock.patch.object(builtins, 'open', return_value=StringIO(IMPORT)): with self.assertRaises(SystemExit) as cm: main(["verify", "-v", "-i", "import.csv"]) self.assertStdOut("") self.assertStdErr("No errors found.") self.assertEqual(cm.exception.code, None)
def test_import_stdin(self): """ Import from stdin. """ with mock.patch("sys.stdin", StringIO(IMPORT)): main(["import", "-n"])