def test_runner_implicit_program_run(): try: sys.argv.append('-f') sys.argv.append("tests/fld_test_program.txt") runner.clean_up() runner.parse_args() runner.main() except Exception as e: raise e
def test_runner_stream_input(): with open("tests/fld_test_program.txt", 'rt') as f: sys.stdin = f try: sys.argv.append('-p') runner.clean_up() runner.parse_args() assert runner.from_pipe assert not runner.from_file runner.main(False) except Exception as e: raise e
def test_debug(): try: sys.argv.pop() sys.argv.pop() sys.argv.append('-f') sys.argv.append("tests/fld_test_program.txt") sys.argv.append('--debug') runner.clean_up() runner.parse_args() assert '-f' not in sys.argv assert runner.from_file assert not runner.from_pipe assert runner.debug runner.main(False) except Exception as e: raise e
def setUp(self): self.parser = parse_args() self.cur_dir = Path.cwd() self.setting_path = str( self.cur_dir.joinpath('src/tests/input/settings.toml')) self.credential_path = str( self.cur_dir.joinpath('src/tests/input/creds.json'))
def test_parse_args(self): args = parse_args(['path']) self.assertEqual( args, Namespace(path='path', enablement_timeout=60, total_timeout=60, log_count=2, include_group=None, exclude_group=None, include_command=None, exclude_command=None, dry_run=False, run_once=False, restart=False, expire_time=None, replay=None))
def test_parse_args_non_default_values_set_run_once(self): args = parse_args(['path', '--enablement-timeout', '30', '--log-count', '4', '--include-group', 'net', '--exclude-group', Kill.group, '--include-command', 'deny-all', '--exclude-command', 'deny-incoming', '--dry-run', '--run-once']) self.assertEqual( args, Namespace(path='path', enablement_timeout=30, total_timeout=30, log_count=4, include_group='net', exclude_group=Kill.group, include_command='deny-all', exclude_command='deny-incoming', dry_run=True, run_once=True, restart=False, expire_time=None, replay=None))
def test_parse_args_non_default_values(self): args = parse_args(['path', '--enablement-timeout', '30', '--total-timeout', '600', '--log-count', '4', '--include-group', 'net', '--exclude-group', Kill.group, '--include-command', 'deny-all', '--exclude-command', 'deny-incoming', '--dry-run', '--restart', '--expire-time', '111.11', '--replay', '/path/to/foo']) self.assertEqual( args, Namespace(path='path', enablement_timeout=30, total_timeout=600, log_count=4, include_group='net', exclude_group=Kill.group, include_command='deny-all', exclude_command='deny-incoming', dry_run=True, run_once=False, restart=True, expire_time=111.11, replay='/path/to/foo'))
def test_display_all_commands_is_called(self): with patch('runner.display_all_commands', autospec=True) as mock: parse_args(['path']) mock.assert_called_once_with()
def test_parse_args_error_total_timeout_and_run_once_set(self): with parse_error(self) as stderr: parse_args(['path', '--total-timeout', '20', '--run-once']) self.assertIn('Conflicting request:', stderr.getvalue())
def test_parse_args_error_enablement_timeout_less_than_zero(self): with parse_error(self) as stderr: parse_args(['path', '--total-timeout', '5', '--enablement-timeout', '-1']) self.assertIn('Invalid enablement-timeout value:', stderr.getvalue())
def test_parse_args_error_enablement_greater_than_total_timeout(self): with parse_error(self) as stderr: parse_args(['path', '--total-timeout', '1', '--enablement-timeout', '5']) self.assertIn('total-timeout can not be less than enablement-timeout', stderr.getvalue())