def test_timeout_0(self, p_sys, p_main): p_sys.argv = ['script.py', '-d', 'example.com', '--timeout', '0'] expected = self.defaults.copy() expected['domains'] = ['example.com'] expected['timeout'] = 0 main.run_from_cli() p_main.assert_called_once_with(**expected)
def test_timeout_out_exists(self, p_sys, p_main, p_isfile): p_sys.argv = ['script.py', '-d', 'example.com', '--out', 'out.csv'] p_isfile.return_value = True msg = 'Output file already exists. Overwrite: "-f" or append: "-a"' with self.assertRaisesRegexp(DocoptExit, msg): main.run_from_cli() p_main.assert_not_called()
def test_log(self, p_sys, p_main): p_sys.argv = ['script.py', '-d', 'example.com', '--log', 'foo.log'] expected = self.defaults.copy() expected['domains'] = ['example.com'] expected['log_file'] = 'foo.log' main.run_from_cli() p_main.assert_called_once_with(**expected)
def test_yesheader_noheader_omg_what(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com', '--header', '--noheader' ] msg = 'Specify either -e or -n but not both.' with self.assertRaisesRegexp(DocoptExit, msg): main.run_from_cli() p_main.assert_not_called()
def test_timeout_out(self, p_sys, p_main): p_sys.argv = ['script.py', '-d', 'example.com', '--out', 'out.csv'] expected = self.defaults.copy() expected['domains'] = ['example.com'] expected['out_file'] = 'out.csv' expected['overwrite'] = True expected['header'] = True main.run_from_cli() p_main.assert_called_once_with(**expected)
def test_timeout_a_poem(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com', '--timeout', 'Tomorrow keeps turning around' ] msg = 'Timeout has to be a number.' with self.assertRaisesRegexp(DocoptExit, msg): main.run_from_cli() p_main.assert_not_called()
def test_min_valid(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com,example.net', ] expected = self.defaults.copy() expected['domains'] = ['example.com', 'example.net'] main.run_from_cli() p_main.assert_called_once_with(**expected)
def test_nofollow(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com', '--nofollow', ] expected = self.defaults.copy() expected['domains'] = ['example.com'] expected['redirect'] = False main.run_from_cli() p_main.assert_called_once_with(**expected)
def test_invalid_file(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com', '-i', 'foo.csv', ] msg = 'Input file does not exist.' with self.assertRaisesRegexp(DocoptExit, msg): main.run_from_cli() p_main.assert_not_called()
def test_invalid_verbosity(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com', '-V', '7', ] msg = 'Verbosity not one of: 0, 1, 2, 3, 4' with self.assertRaisesRegexp(DocoptExit, msg): main.run_from_cli() p_main.assert_not_called()
def test_timeout_huge(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com', '--timeout', '10123', ] msg = 'Timeout has to be 300 or less.' with self.assertRaisesRegexp(DocoptExit, msg): main.run_from_cli() p_main.assert_not_called()
def test_timeout_negative(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com', '--timeout', '-1', ] msg = 'Timeout has to be 0 or greater.' with self.assertRaisesRegexp(DocoptExit, msg): main.run_from_cli() p_main.assert_not_called()
def test_verbosity_and_input(self, p_sys, p_main): p_sys.argv = [ 'script.py', '-d', 'example.com', '-V', '1', '-i', 'SampleLinks.csv', ] expected = self.defaults.copy() expected['domains'] = ['example.com'] expected['verbosity'] = 1 expected['in_file'] = 'SampleLinks.csv' main.run_from_cli() p_main.assert_called_once_with(**expected)
def test_timeout_out_append_but_new(self, p_sys, p_main, p_isfile): p_sys.argv = [ 'script.py', '-d', 'example.com', '--out', 'out.csv', '--append', ] p_isfile.return_value = False expected = self.defaults.copy() expected['domains'] = ['example.com'] expected['out_file'] = 'out.csv' expected['header'] = True expected['overwrite'] = False main.run_from_cli() p_main.assert_called_once_with(**expected)
def test_default(self, p_sys, p_main): p_sys.argv = [] with self.assertRaises(DocoptExit): main.run_from_cli() p_main.assert_not_called()