def test_export_bank13(self): """ Export of bank 13 (non-existing). """ with self.assertRaises(SystemExit) as cm: main(["export", "-n", "-b", "13"]) self.assertNotEqual(cm.exception.code, None)
def test_help(self): """ Show help. """ with self.assertRaises(SystemExit) as cm: main(["help"]) self.assertEqual(cm.exception.code, None)
def test_usage(self): """ Show usage. """ with self.assertRaises(SystemExit) as cm: main([]) 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_version(self): """ Show version. """ with self.assertRaises(SystemExit) as cm: main(["-V"]) self.assertStdOut(VERSION) self.assertEqual(cm.exception.code, None)
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_export_outfile(self): """ Write export to file. """ with mock.patch.object(builtins, "open", mock.mock_open()): main(["export", "-n", "-s", "-o", "output.csv"]) with self.assertRaises(SystemExit) as cm: main(["export", "-n", "-s", "-o", "/path/that/does/not/exist/output.csv"]) self.assertNotEqual(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_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_export_outfile(self): """ Write export to file. """ with mock.patch.object(builtins, "open", mock.mock_open()): main(["export", "-n", "-s", "-o", "output.csv"]) with self.assertRaises(SystemExit) as cm: main([ "export", "-n", "-s", "-o", "/path/that/does/not/exist/output.csv" ]) self.assertNotEqual(cm.exception.code, None)
def test_export_sparse_bank2(self): """ Sparse export of bank 2. """ main(["export", "-n", "-s", "-b", "2"]) self.assertStdOut(EXPORT_BANK2)
def test_export_sparse(self): """ Sparse export of all channels. """ main(["export", "-n", "-s"]) self.assertStdOut(EXPORT_SPARSE)
def test_import_stdin(self): """ Import from stdin. """ with mock.patch("sys.stdin", StringIO(IMPORT)): main(["import", "-n"])
def test_export(self): """ Normal export of all channels. """ main(["export", "-n"]) self.assertStdOut(EXPORT)
def test_export_sparse_bank2_empty(self): """ Sparse export of bank 2 including empty channels. """ main(["export", "-n", "-s", "-b", "2", "-e"]) self.assertStdOut(EXPORT_BANK2_EMPTY)