def run_all(test_file: str, target_file: str): test_file_path = path.join(config_file_path(test_file)) target_file_path = path.join(config_file_path(target_file)) env_vars = dict(os.environ) context, config = Pluma.create_context_from_files(test_file_path, target_file_path, env_vars) Pluma.print_tests(config) Pluma.run(context, config, check_only=True)
def test_Pluma_create_target_context_should_warn_if_variable_overwritten_by_env( capsys, monkeypatch): monkeypatch.setenv('mymessage', 'env message') Pluma.create_target_context(config_file_path('variable-sub-target')) stdout = capsys.readouterr().out assert f'"mymessage" defined in both environment variables and target config.{os.linesep} Using environment: env message' in stdout
def test_Pluma_create_target_context_env_vars_should_override_target_variables(monkeypatch): monkeypatch.setenv('mymessage', 'env message') env_vars = dict(os.environ) config = Pluma.load_config_file(config_file_path('variable-sub-target'), 'Target Config', env_vars) context = Pluma.create_target_context(config, env_vars) assert context.variables['mymessage'] == 'env message'
def test_Pluma_create_target_context_variables_should_reflect_env_vars(monkeypatch): monkeypatch.setenv('abc', 'def') env_vars = dict(os.environ) config = Pluma.load_config_file(config_file_path('minimal-target'), 'Target Config', env_vars) context = Pluma.create_target_context(config, env_vars) assert context.variables['abc'] == 'def'
def test_Pluma_create_context_from_files(): test_file_path = config_file_path('minimal-tests') target_file_path = config_file_path('minimal-target') context, config = Pluma.create_context_from_files(test_file_path, target_file_path) assert isinstance(context, PlumaContext) assert isinstance(config, TestsConfig)
def test_Pluma_create_target_context_variables_should_reflect_env_vars( monkeypatch): monkeypatch.setenv('abc', 'def') context = Pluma.create_target_context(config_file_path('minimal-target')) assert context.variables['abc'] == 'def'
def main(): args = parse_arguments() set_log_mode(args) tests_config_path = args.config target_config_path = args.target if args.plugin: for plugin_dir in args.plugin: load_plugin_modules(plugin_dir) try: command = args.command if command in [RUN_COMMAND, CHECK_COMMAND, TESTS_COMMAND]: env_vars = dict(os.environ) pluma_context, tests_config = Pluma.create_context_from_files( tests_config_path, target_config_path, env_vars) if command == RUN_COMMAND: success = Pluma.run(pluma_context, tests_config) exit(0 if success else 1) elif command == CHECK_COMMAND: Pluma.run(pluma_context, tests_config, check_only=True) elif command == TESTS_COMMAND: Pluma.print_tests(tests_config) elif command == CLEAN_COMMAND: Pluma.clean(args.force) elif command == VERSION_COMMAND: log.log(Pluma.version(), level=LogLevel.IMPORTANT) except TestsConfigError as e: log.error([ f'Error while parsing the tests configuration ({tests_config_path}):', str(e) ]) exit(-2) except TargetConfigError as e: log.error([ f'Error while parsing the target configuration ({target_config_path}):', str(e) ]) exit(-3) except TestsBuildError as e: log.error(['Error while building tests:', str(e)]) exit(-4) except Exception as e: if log.mode in [LogMode.VERBOSE, LogMode.DEBUG]: traceback.print_exc() log.error(repr(e)) exit(-1)
def test_Pluma_create_target_context_env_vars_should_override_target_variables( monkeypatch): monkeypatch.setenv('mymessage', 'env message') context = Pluma.create_target_context( config_file_path('variable-sub-target')) assert context.variables['mymessage'] == 'env message'
def test_Pluma_create_context_from_yaml_strs(): with open(config_file_path('minimal-tests'), 'r') as f: tests_yaml = f.read() with open(config_file_path('minimal-target'), 'r') as f: target_yaml = f.read() context, config = Pluma.create_context_from_yaml_strs(tests_yaml, target_yaml) assert isinstance(context, PlumaContext) assert isinstance(config, TestsConfig)
def test_Pluma_create_target_context_env_vars_should_override_target_variables( ): env = dict(os.environ) try: os.environ['mymessage'] = 'env message' context = Pluma.create_target_context( config_file_path('variable-sub-target')) assert context.variables['mymessage'] == 'env message' finally: os.environ.clear() os.environ.update(env)
def test_Pluma_create_target_context_variables_should_reflect_env_vars(): env = dict(os.environ) try: os.environ['abc'] = 'def' context = Pluma.create_target_context( config_file_path('minimal-target')) assert context.variables['abc'] == 'def' finally: os.environ.clear() os.environ.update(env)
def test_Pluma_create_target_context_should_parse_target_variables(): context = Pluma.create_target_context( config_file_path('variable-sub-target')) assert context.variables['mymessage'] == 'echo hello script!'
def run_all(test_file: str, target_file: str): test_file_path = path.join(config_file_path(test_file)) target_file_path = path.join(config_file_path(target_file)) Pluma.execute_tests(test_file_path, target_file_path) Pluma.execute_run(test_file_path, target_file_path, check_only=True)
def test_Pluma_create_target_context_should_parse_target_variables(): env_vars = dict(os.environ) config = Pluma.load_config_file(config_file_path('variable-sub-target'), 'Target Config', env_vars) context = Pluma.create_target_context(config, env_vars) assert context.variables['mymessage'] == 'echo hello script!'