def setup_class(cls): """Set the test up.""" cls.schema = json.load(open(AGENT_CONFIGURATION_SCHEMA)) cls.resolver = jsonschema.RefResolver( make_jsonschema_base_uri( Path(CONFIGURATION_SCHEMA_DIR).absolute()), cls.schema, ) cls.validator = Draft4Validator(cls.schema, resolver=cls.resolver) cls.runner = CliRunner() cls.agent_name = "myagent" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() os.chdir(cls.t) cls.cli_config_file = f"{cls.t}/cli_config.yaml" cls.cli_config_patch = patch("aea.cli.utils.config.CLI_CONFIG_PATH", cls.cli_config_file) cls.cli_config_patch.start() result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]) assert result.exit_code == 0 cls.result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "create", "--local", cls.agent_name], standalone_mode=False, ) cls.agent_config = cls._load_config_file(cls.agent_name)
def setup_class(cls): """Set the test up.""" cls.runner = CliRunner() cls.agent_name = "myagent" cls.resource_name = "myresource" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() cls.schema = json.load(open(PROTOCOL_CONFIGURATION_SCHEMA)) cls.resolver = jsonschema.RefResolver( make_jsonschema_base_uri( Path(CONFIGURATION_SCHEMA_DIR).absolute()), cls.schema, ) cls.validator = Draft4Validator(cls.schema, resolver=cls.resolver) os.chdir(cls.t) result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]) assert result.exit_code == 0 result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "create", "--local", cls.agent_name], standalone_mode=False, ) assert result.exit_code == 0 os.chdir(cls.agent_name) # scaffold protocol cls.result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "scaffold", "protocol", cls.resource_name], standalone_mode=False, )
def setup_class(cls): """Set up the test class.""" cls.schema = json.load(open(SKILL_CONFIGURATION_SCHEMA)) cls.resolver = jsonschema.RefResolver( make_jsonschema_base_uri( Path(CONFIGURATION_SCHEMA_DIR).absolute()), cls.schema, ) cls.validator = Draft4Validator(cls.schema, resolver=cls.resolver)
def test_windows_uri_path(): """Test uri path on running platform.""" path = Path("aea", "configurations").absolute() output = make_jsonschema_base_uri(path) if os.name == "nt": assert output == f"file:///{'/'.join(path.parts)}/" else: assert output == f"file:/{'/'.join(path.parts)}/"
def test_windows_uri_path(system): """Test windows uri path.""" dir = Path("aea", "configurations").absolute() with mock.patch.object(os, "name", system): output = make_jsonschema_base_uri(dir) if system == "nt": assert output == f"file:///{'/'.join(dir.parts)}/" else: assert output == f"file:/{'/'.join(dir.parts)}/"
def test_validate_agent_config(): """Test that the validation of the agent configuration file works correctly.""" agent_config_file = yaml.safe_load( open(os.path.join(CUR_PATH, "data", "aea-config.example.yaml"))) agent_config_schema = json.load(open(AGENT_CONFIGURATION_SCHEMA)) resolver = jsonschema.RefResolver( make_jsonschema_base_uri(Path(CONFIGURATION_SCHEMA_DIR)), agent_config_schema) validate(instance=agent_config_file, schema=agent_config_schema, resolver=resolver)
def test_config_validation(schema_file_path, config_file_path): """Test configuration validation.""" # TODO a bit inefficient to load each schema everytime; consider making the validators as fixtures. schema = json.load(open(schema_file_path)) resolver = jsonschema.RefResolver( make_jsonschema_base_uri(Path(CONFIGURATION_SCHEMA_DIR).absolute()), schema, ) validator = Draft4Validator(schema, resolver=resolver) config_data = list(yaml.safe_load_all(open(config_file_path))) validator.validate(instance=config_data[0])
def setup_class(cls): """Set the test up.""" cls.runner = CliRunner() cls.agent_name = "myagent" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() dir_path = Path("packages") tmp_dir = cls.t / dir_path src_dir = cls.cwd / Path(ROOT_DIR, dir_path) shutil.copytree(str(src_dir), str(tmp_dir)) shutil.copyfile( Path(CUR_PATH, "data", "sample_specification.yaml"), Path(cls.t, "sample_specification.yaml"), ) cls.path_to_specification = str(Path("..", "sample_specification.yaml")) cls.schema = json.load(open(PROTOCOL_CONFIGURATION_SCHEMA)) cls.resolver = jsonschema.RefResolver( make_jsonschema_base_uri( Path(CONFIGURATION_SCHEMA_DIR).absolute()), cls.schema, ) cls.validator = Draft4Validator(cls.schema, resolver=cls.resolver) # create an agent os.chdir(cls.t) result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]) assert result.exit_code == 0 cls.create_result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "create", "--local", cls.agent_name], standalone_mode=False, ) os.chdir(cls.agent_name) # generate protocol cls.result = cls.runner.invoke( cli, [ *CLI_LOG_OPTION, "generate", "protocol", "--l", "cpp", cls.path_to_specification, ], standalone_mode=False, ) os.chdir(cls.cwd)
def setup(self): """Set the test up.""" self.schema = json.load(open(AGENT_CONFIGURATION_SCHEMA)) self.resolver = jsonschema.RefResolver( make_jsonschema_base_uri(Path(CONFIGURATION_SCHEMA_DIR).absolute()), self.schema, ) self.validator = Draft4Validator(self.schema, resolver=self.resolver) self.agent_name = "myagent" self.cwd = os.getcwd() self.t = tempfile.mkdtemp() os.chdir(self.t)
def setup_class(cls): """Set the test up.""" cls.schema = json.load(open(AGENT_CONFIGURATION_SCHEMA)) cls.resolver = jsonschema.RefResolver( make_jsonschema_base_uri(Path(CONFIGURATION_SCHEMA_DIR)), cls.schema) cls.validator = Draft4Validator(cls.schema, resolver=cls.resolver) cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() # copy the 'dummy_aea' directory in the parent of the agent folder. shutil.copytree(Path(CUR_PATH, "data", "dummy_aea"), Path(cls.t, "dummy_aea")) cls.runner = CliRunner() os.chdir(Path(cls.t, "dummy_aea")) cls.result = cls.runner.invoke(cli, [*CLI_LOG_OPTION, "freeze"], standalone_mode=False)
def setup_class(cls): """Set the test up.""" cls.runner = CliRunner() cls.agent_name = "myagent" cls.resource_name = "myresource" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() dir_path = Path("packages") tmp_dir = cls.t / dir_path src_dir = cls.cwd / Path(ROOT_DIR, dir_path) shutil.copytree(str(src_dir), str(tmp_dir)) cls.schema = json.load(open(CONNECTION_CONFIGURATION_SCHEMA)) cls.resolver = jsonschema.RefResolver( make_jsonschema_base_uri( Path(CONFIGURATION_SCHEMA_DIR).absolute()), cls.schema, ) cls.validator = Draft4Validator(cls.schema, resolver=cls.resolver) os.chdir(cls.t) result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR]) assert result.exit_code == 0 result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "create", "--local", cls.agent_name], standalone_mode=False, ) assert result.exit_code == 0 os.chdir(cls.agent_name) # scaffold connection cls.result = cls.runner.invoke( cli, [ *CLI_LOG_OPTION, "scaffold", "--with-symlinks", "connection", cls.resource_name, ], standalone_mode=False, )
def setup(self): """Set the test up.""" self.runner = CliRunner() self.schema = json.load(open(AGENT_CONFIGURATION_SCHEMA)) self.resolver = jsonschema.RefResolver( make_jsonschema_base_uri(Path(CONFIGURATION_SCHEMA_DIR).absolute()), self.schema, ) self.validator = Draft4Validator(self.schema, resolver=self.resolver) self.agent_name = "myagent" self.cwd = os.getcwd() self.t = tempfile.mkdtemp() os.chdir(self.t) result = self.runner.invoke( cli, [*CLI_LOG_OPTION, "init", "--local", "--author", "test_author"], ) assert result.exit_code == 0
def setup_class(cls): """Set the test up.""" cls.runner = CliRunner() cls.agent_name = "myagent" cls.resource_name = "myresource" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() dir_path = Path("packages") tmp_dir = cls.t / dir_path src_dir = cls.cwd / Path(ROOT_DIR, dir_path) shutil.copytree(str(src_dir), str(tmp_dir)) cls.schema = json.load(open(PROTOCOL_CONFIGURATION_SCHEMA)) cls.resolver = jsonschema.RefResolver( make_jsonschema_base_uri(Path(CONFIGURATION_SCHEMA_DIR).absolute()), cls.schema, ) cls.validator = Draft4Validator(cls.schema, resolver=cls.resolver) os.chdir(cls.t) result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "init", "--local", "--author", AUTHOR] ) assert result.exit_code == 0 result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "create", "--local", cls.agent_name], standalone_mode=False, ) assert result.exit_code == 0 os.chdir(cls.agent_name) # scaffold protocol with patch("click.confirm", return_value=True) as confirm_mock: cls.result = cls.runner.invoke( cli, [*CLI_LOG_OPTION, "scaffold", "protocol", cls.resource_name], standalone_mode=False, ) confirm_mock.assert_called_once_with( "We highly recommend auto-generating protocols with the aea generate command. Do you really want to continue scaffolding?" )