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" ])
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
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
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
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
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
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
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
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
def test_two_actions(self): """ Called with two actions. """ with pytest.raises(SystemExit): tjcim.parse_args(["--get-line", "3", "--remove-line", "4"])
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"])
def test_both_quiet_and_verbose(self): """ Called with both -v and -q. """ with pytest.raises(SystemExit): tjcim.parse_args(["-v", "-q"])
def test_merge_one_file(self): """ Merge called with one file should error. """ with pytest.raises(SystemExit): tjcim.parse_args(["--merge", "blah1.csv"])
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
def test_no_input(self): """ Called without an input. """ with pytest.raises(SystemExit): tjcim.parse_args(["--filter", "fun", "output", "blah.fun.csv"])
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
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
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
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
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
def test_no_input(self): """ Called without an input. """ with pytest.raises(SystemExit): tjcim.parse_args(["--filter", "fun", "output", "blah.fun.csv"])
def test_both_quiet_and_verbose(self): """ Called with both -v and -q. """ with pytest.raises(SystemExit): tjcim.parse_args(["-v", "-q"])
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
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
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
def test_two_actions(self): """ Called with two actions. """ with pytest.raises(SystemExit): tjcim.parse_args(["--get-line", "3", "--remove-line", "4"])
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
def test_merge_one_file(self): """ Merge called with one file should error. """ with pytest.raises(SystemExit): tjcim.parse_args(["--merge", "blah1.csv"])
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
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