def test_debug_file_out(self): test_name = 'debug_file_out' with self.check_debug_log(MOCKED_DATA, test_name) as fname: check_pycolor_main(self, ['--debug-log-out', fname, 'free', '-h'], MOCKED_DATA, test_name, patch_stdout=True)
def test_ls_stdin(self): name = 'ls_stdin' with open(os.path.join(MOCKED_DATA, name + '.txt'), 'r') as stdin: check_pycolor_main(self, ['--stdin', 'ls', '-l'], MOCKED_DATA, name, stdin=stdin)
def test_debug_format(self): check_pycolor_main(self, [ '--debug-format', 'this %C(lr)is %C(und;ly)a %C(^und;bol;bli;g)test' ], MOCKED_DATA, 'debug_format', patch_stdout=True)
def test_debug_color(self): #pylint: disable=invalid-name def get_terminal_size(_=None): TerminalSize = namedtuple('terminal_size', ['columns', 'lines']) return TerminalSize(80, 24) with patch(os, 'get_terminal_size', get_terminal_size): check_pycolor_main(self, ['--debug-color'], MOCKED_DATA, 'debug_color', patch_stdout=True)
def test_copy_sample_config(self): self.assertTrue(os.path.isdir(SAMPLE_CONFIG_DIR)) with tempfile.TemporaryDirectory() as tmpdir: tmpconfig = os.path.join(tmpdir, 'config') with patch(sys, 'stdout', textstream()), patch(pycolor, 'CONFIG_DIR', tmpconfig): check_pycolor_main(self, ['--version'], MOCKED_DATA, 'empty', patch_sample_config_dir=False) self.assertListEqual(sorted(os.listdir(SAMPLE_CONFIG_DIR)), sorted(os.listdir(tmpconfig)))
def test_stdin_config_invalid_profile(self): with patch_stderr() as stream: stdin = textstream() check_pycolor_main(self, ['--stdin', 'rsync'], MOCKED_DATA, 'invalid_profile', stdin=stdin) stream.seek(0) result = stream.read() self.assertTrue( result.startswith( '\x1b[91merror\x1b[0m: \x1b[93m%s\x1b[0m: ' % (os.path.join(MOCKED_DATA, 'invalid_profile.json'))))
def test_stdin_config_invalid_pattern(self): with patch_stderr() as stream: stdin = textstream() with self.assertRaises(SystemExit): check_pycolor_main(self, ['--stdin', 'rsync'], MOCKED_DATA, 'invalid_pattern', stdin=stdin) stream.seek(0) result = stream.read() self.assertEqual( result, '\x1b[91merror\x1b[0m: "expression": regex nothing to repeat at position 0\n' )
def test_load_sample_config(self): self.assertTrue(os.path.isdir(SAMPLE_CONFIG_DIR)) with patch(pycolor, 'CONFIG_DIR', SAMPLE_CONFIG_DIR),\ patch(pycolor, 'CONFIG_DEFAULT', os.path.join(SAMPLE_CONFIG_DIR, 'rsync.json')): stdin = textstream() with open(os.path.join(MOCKED_DATA, 'load_sample_config.txt'), 'r') as file: stdin.write(file.read()) stdin.seek(0) check_pycolor_main(self, ['--stdin', 'rsync'], MOCKED_DATA, 'load_sample_config', stdin=stdin, no_load_args=True)
def test_free_tty(self): check_pycolor_main(self, ['free', '-h'], MOCKED_DATA, 'free_tty')
def test_debug_file_v3(self): test_name = 'debug_file_v3' with self.check_debug_log(MOCKED_DATA, test_name) as fname: check_pycolor_main(self, ['-vvv', '--debug-log', fname, 'free', '-h'], MOCKED_DATA, test_name)
def test_ls_timestamp_arg(self): check_pycolor_main(self, ['--timestamp', '--', 'ls', '-l'], MOCKED_DATA, 'ls_timestamp_arg')
def test_ls_debug_v1_no_color(self): check_pycolor_main(self, ['-v', '--color=off', '--', 'ls', '-l'], MOCKED_DATA, 'ls_debug_v1_no_color', patch_stdout=True)
def test_ls_debug_v3(self): check_pycolor_main(self, ['-vvv', '--', 'ls', '-l'], MOCKED_DATA, 'ls_debug_v3', patch_stdout=True)
def test_ls_profile_named(self): check_pycolor_main(self, ['--profile', 'num', '--', 'ls', '-l'], MOCKED_DATA, 'ls_profile_named')
def test_ls_timestamp_arg_default_profile(self): check_pycolor_main(self, ['--timestamp', '--', 'ls', '-l'], MOCKED_DATA, 'ls_timestamp_arg_default_profile')
def test_version(self): with patch_stdout() as stdout: check_pycolor_main(self, ['--version'], MOCKED_DATA, 'empty') stdout.seek(0) self.assertEqual(stdout.read(), pycolor.__version__ + '\n')
def test_ls_profile_none(self): check_pycolor_main(self, ['--no-execv', '--profile=', '--', 'ls', '-l'], MOCKED_DATA, 'ls_profile_none')
def test_from_profile_not_exist(self): with self.assertRaises(SystemExit): check_pycolor_main(self, ['-p=test', 'ls', '-l'], MOCKED_DATA, 'from_profile_not_exist', patch_stderr=True)
def test_unknown_command(self): with self.assertRaises(SystemExit): check_pycolor_main(self, ['this-is-not-a-valid-command-peucrnh'], MOCKED_DATA, 'unknown_command', patch_stderr=True)
def test_ls_profile_fail(self): with self.assertRaises(SystemExit), patch_stderr(): check_pycolor_main(self, ['--profile', 'invalid', '--', 'ls', '-l'], MOCKED_DATA, 'ls_profile_named')
def test_stdin_no_profile_no_cmd_args(self): with self.assertRaises(SystemExit): check_pycolor_main(self, [], MOCKED_DATA, 'stdin_no_profile_no_cmd_args', patch_stdout=True)
def test_df_color_alias(self): check_pycolor_main(self, ['df', '-h'], MOCKED_DATA, 'df_color_alias')