Exemplo n.º 1
0
 def test_two_inputs(self):
     """ Called with two inputs. """
     with pytest.raises(SystemExit):
         tjcim.parse_args([
             "--file", "blah.csv", "--http-get-file",
             "http://www.google.com"
         ])
Exemplo n.º 2
0
 def test_main_no_action(self, tmpdir):
     """ Test main with no action. """
     expected = [
         ['John', 'Doe', '120 jefferson st.', 'Riverside', 'NJ', '08075'],
         ['Jack', 'McGinnis', '220 hobo Av.', 'Phila', 'PA', '09119'],
         [
             'John "Da Man"', 'Repici', '120 Jefferson St.', 'Riverside',
             'NJ', '08075'
         ],
         [
             'Stephen', 'Tyler', '7452 Terrace "At the Plaza" road',
             'SomeTown', 'SD', '91234'
         ],
         ['', 'Blankman', '', 'SomeTown', 'SD', '00298'],
         [
             'Joan "the bone", Anne', 'Jet', '9th, at Terrace plc',
             'Desert City', 'CO', '00123'
         ],
     ]
     output_file = str(tmpdir.join("no_action.csv"))
     args = tjcim.parse_args([
         "--file",
         os.path.join(CSV_FOLDER, "addresses.csv"), "--output-file",
         output_file
     ])
     tjcim.main(args)
     assert os.path.isfile(output_file)
     assert tjcim.csv_to_list(output_file) == expected
Exemplo n.º 3
0
 def test_main_http(self, tmpdir):
     """ Test main with argument http """
     expected = [
         ['Jack', 'McGinnis', '220 hobo Av.', 'Phila', 'PA', '09119'],
     ]
     output_file = str(tmpdir.join("http_get_line_2.csv"))
     args = tjcim.parse_args(["--http-get-file",
                              "https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv",
                              "--get-line", "2", "--output-file", output_file])
     tjcim.main(args)
     assert os.path.isfile(output_file)
     assert tjcim.csv_to_list(output_file) == expected
Exemplo n.º 4
0
 def test_main_http(self, tmpdir):
     """ Test main with argument http """
     expected = [
         ['Jack', 'McGinnis', '220 hobo Av.', 'Phila', 'PA', '09119'],
     ]
     output_file = str(tmpdir.join("http_get_line_2.csv"))
     args = tjcim.parse_args([
         "--http-get-file",
         "https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv",
         "--get-line", "2", "--output-file", output_file
     ])
     tjcim.main(args)
     assert os.path.isfile(output_file)
     assert tjcim.csv_to_list(output_file) == expected
Exemplo n.º 5
0
 def test_main_merge(self, tmpdir):
     """ Test main with merge. """
     expected = [
         ['John', 'Doe', '120 jefferson st.', 'Riverside', 'NJ', '08075'],
         ['John', 'M', '30', '68', '210'],
     ]
     output_file = str(tmpdir.join("merge_filter_John.csv"))
     args = tjcim.parse_args(["--merge",
                              os.path.join(CSV_FOLDER, "addresses.csv"),
                              os.path.join(CSV_FOLDER, "airtravel.csv"),
                              os.path.join(CSV_FOLDER, "biostats.csv"),
                              "--filter", "John", "--output-file", output_file])
     tjcim.main(args)
     assert os.path.isfile(output_file)
     assert tjcim.csv_to_list(output_file) == expected
Exemplo n.º 6
0
 def test_main_no_action(self, tmpdir):
     """ Test main with no action. """
     expected = [
         ['John', 'Doe', '120 jefferson st.', 'Riverside', 'NJ', '08075'],
         ['Jack', 'McGinnis', '220 hobo Av.', 'Phila', 'PA', '09119'],
         ['John "Da Man"', 'Repici', '120 Jefferson St.', 'Riverside', 'NJ', '08075'],
         ['Stephen', 'Tyler', '7452 Terrace "At the Plaza" road', 'SomeTown', 'SD', '91234'],
         ['', 'Blankman', '', 'SomeTown', 'SD', '00298'],
         ['Joan "the bone", Anne', 'Jet', '9th, at Terrace plc', 'Desert City', 'CO', '00123'],
     ]
     output_file = str(tmpdir.join("no_action.csv"))
     args = tjcim.parse_args(["--file", os.path.join(CSV_FOLDER, "addresses.csv"),
                              "--output-file", output_file])
     tjcim.main(args)
     assert os.path.isfile(output_file)
     assert tjcim.csv_to_list(output_file) == expected
Exemplo n.º 7
0
 def test_main_file(self, tmpdir):
     """ Test main with argument file """
     expected = [
         ['John', 'Doe', '120 jefferson st.', 'Riverside', 'NJ', '08075'],
         ['Jack', 'McGinnis', '220 hobo Av.', 'Phila', 'PA', '09119'],
         ['John "Da Man"', 'Repici', '120 Jefferson St.', 'Riverside', 'NJ', '08075'],
         ['', 'Blankman', '', 'SomeTown', 'SD', '00298'],
         ['Joan "the bone", Anne', 'Jet', '9th, at Terrace plc', 'Desert City', 'CO', '00123'],
     ]
     output_file = str(tmpdir.join("addresses_remove_line_4.csv"))
     args = tjcim.parse_args(["--file", os.path.join(CSV_FOLDER, "addresses.csv"),
                              "--remove-line", "4", "--output-file",
                              output_file])
     tjcim.main(args)
     assert os.path.isfile(output_file)
     assert tjcim.csv_to_list(output_file) == expected
Exemplo n.º 8
0
 def test_main_merge(self, tmpdir):
     """ Test main with merge. """
     expected = [
         ['John', 'Doe', '120 jefferson st.', 'Riverside', 'NJ', '08075'],
         ['John', 'M', '30', '68', '210'],
     ]
     output_file = str(tmpdir.join("merge_filter_John.csv"))
     args = tjcim.parse_args([
         "--merge",
         os.path.join(CSV_FOLDER, "addresses.csv"),
         os.path.join(CSV_FOLDER, "airtravel.csv"),
         os.path.join(CSV_FOLDER, "biostats.csv"), "--filter", "John",
         "--output-file", output_file
     ])
     tjcim.main(args)
     assert os.path.isfile(output_file)
     assert tjcim.csv_to_list(output_file) == expected
Exemplo n.º 9
0
 def test_main_file(self, tmpdir):
     """ Test main with argument file """
     expected = [
         ['John', 'Doe', '120 jefferson st.', 'Riverside', 'NJ', '08075'],
         ['Jack', 'McGinnis', '220 hobo Av.', 'Phila', 'PA', '09119'],
         [
             'John "Da Man"', 'Repici', '120 Jefferson St.', 'Riverside',
             'NJ', '08075'
         ],
         ['', 'Blankman', '', 'SomeTown', 'SD', '00298'],
         [
             'Joan "the bone", Anne', 'Jet', '9th, at Terrace plc',
             'Desert City', 'CO', '00123'
         ],
     ]
     output_file = str(tmpdir.join("addresses_remove_line_4.csv"))
     args = tjcim.parse_args([
         "--file",
         os.path.join(CSV_FOLDER, "addresses.csv"), "--remove-line", "4",
         "--output-file", output_file
     ])
     tjcim.main(args)
     assert os.path.isfile(output_file)
     assert tjcim.csv_to_list(output_file) == expected
Exemplo n.º 10
0
 def test_two_actions(self):
     """ Called with two actions. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["--get-line", "3", "--remove-line", "4"])
Exemplo n.º 11
0
 def test_two_inputs(self):
     """ Called with two inputs. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["--file", "blah.csv", "--http-get-file", "http://www.google.com"])
Exemplo n.º 12
0
 def test_both_quiet_and_verbose(self):
     """ Called with both -v and -q. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["-v", "-q"])
Exemplo n.º 13
0
 def test_merge_one_file(self):
     """ Merge called with one file should error. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["--merge", "blah1.csv"])
Exemplo n.º 14
0
 def test_merge_remove_line_output(self, test_args, expected):
     """ test parse args with valid merge input, action and output. """
     res = tjcim.parse_args(test_args)
     assert (res.merge, res.remove_line, res.output_file) == expected
Exemplo n.º 15
0
 def test_no_input(self):
     """ Called without an input. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["--filter", "fun", "output", "blah.fun.csv"])
Exemplo n.º 16
0
 def test_quiet(self):
     """ Test logger is set to ERROR only. """
     assert tjcim.log.isEnabledFor(logging.WARN) is True
     tjcim.parse_args(["--file", "blah.csv", "-q", "--remove-line", "3"])
     assert tjcim.log.isEnabledFor(logging.WARN) is False
     assert tjcim.log.isEnabledFor(logging.ERROR) is True
Exemplo n.º 17
0
 def test_merge_remove_line_output(self, test_args, expected):
     """ test parse args with valid merge input, action and output. """
     res = tjcim.parse_args(test_args)
     assert (res.merge, res.remove_line, res.output_file) == expected
Exemplo n.º 18
0
 def test_info(self):
     """ Test that with no verbosity args the script remains at INFO. """
     tjcim.parse_args(["--file", "blah.csv", "--remove-line", "3"])
     assert tjcim.log.isEnabledFor(logging.INFO) is True
Exemplo n.º 19
0
 def test_quiet(self):
     """ Test logger is set to ERROR only. """
     assert tjcim.log.isEnabledFor(logging.WARN) is True
     tjcim.parse_args(["--file", "blah.csv", "-q", "--remove-line", "3"])
     assert tjcim.log.isEnabledFor(logging.WARN) is False
     assert tjcim.log.isEnabledFor(logging.ERROR) is True
Exemplo n.º 20
0
 def test_verbose(self):
     """ Test logger is set to DEBUG. """
     assert tjcim.log.isEnabledFor(logging.DEBUG) is False
     tjcim.parse_args(["--file", "blah.csv", "-v", "--remove-line", "3"])
     assert tjcim.log.isEnabledFor(logging.DEBUG) is True
Exemplo n.º 21
0
 def test_no_input(self):
     """ Called without an input. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["--filter", "fun", "output", "blah.fun.csv"])
Exemplo n.º 22
0
 def test_both_quiet_and_verbose(self):
     """ Called with both -v and -q. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["-v", "-q"])
Exemplo n.º 23
0
 def test_verbose(self):
     """ Test logger is set to DEBUG. """
     assert tjcim.log.isEnabledFor(logging.DEBUG) is False
     tjcim.parse_args(["--file", "blah.csv", "-v", "--remove-line", "3"])
     assert tjcim.log.isEnabledFor(logging.DEBUG) is True
Exemplo n.º 24
0
 def test_http_get_line_output(self, test_args, expected):
     """ test parse args with valid http input, action, and output. """
     res = tjcim.parse_args(test_args)
     assert (res.http_get_file, res.get_line, res.output_file) == expected
Exemplo n.º 25
0
 def test_info(self):
     """ Test that with no verbosity args the script remains at INFO. """
     tjcim.parse_args(["--file", "blah.csv", "--remove-line", "3"])
     assert tjcim.log.isEnabledFor(logging.INFO) is True
Exemplo n.º 26
0
 def test_two_actions(self):
     """ Called with two actions. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["--get-line", "3", "--remove-line", "4"])
Exemplo n.º 27
0
 def test_http_get_line_output(self, test_args, expected):
     """ test parse args with valid http input, action, and output. """
     res = tjcim.parse_args(test_args)
     assert (res.http_get_file, res.get_line, res.output_file) == expected
Exemplo n.º 28
0
 def test_merge_one_file(self):
     """ Merge called with one file should error. """
     with pytest.raises(SystemExit):
         tjcim.parse_args(["--merge", "blah1.csv"])
Exemplo n.º 29
0
 def test_file_filter_output(self, test_args, expected):
     """ test parse args with valid file input, action, and output. """
     res = tjcim.parse_args(test_args)
     assert (res.file, res.filter, res.output_file) == expected
Exemplo n.º 30
0
 def test_file_filter_output(self, test_args, expected):
     """ test parse args with valid file input, action, and output. """
     res = tjcim.parse_args(test_args)
     assert (res.file, res.filter, res.output_file) == expected