Skip to content

Commit

Permalink
test: fix the regressed CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantios committed Feb 12, 2025
1 parent ccfd70c commit 6b0c444
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 257 deletions.
7 changes: 3 additions & 4 deletions autonomy/deploy/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2024 Valory AG
# Copyright 2021-2025 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -99,6 +99,7 @@
DEFAULT_AGENT_CPU_LIMIT = float(os.environ.get("AUTONOMY_AGENT_CPU_LIMIT", 1.0))
DEFAULT_AGENT_MEMORY_REQUEST = int(os.environ.get("AUTONOMY_AGENT_MEMORY_REQUEST", 256))
DEFAULT_AGENT_CPU_REQUEST = float(os.environ.get("AUTONOMY_AGENT_CPU_REQUEST", 1.0))
AUTONOMY_PKEY_PASSWORD = "OPEN_AUTONOMY_PRIVATE_KEY_PASSWORD"


def tm_write_to_log() -> bool:
Expand Down Expand Up @@ -729,9 +730,7 @@ def generate_common_vars(self, agent_n: int) -> Dict:
ENV_VAR_ID: agent_n,
ENV_VAR_AEA_AGENT: self.service.agent,
ENV_VAR_LOG_LEVEL: self.log_level,
ENV_VAR_AEA_PASSWORD: os.environ.get(
"OPEN_AUTONOMY_PRIVATE_KEY_PASSWORD", ""
),
ENV_VAR_AEA_PASSWORD: os.environ.get(AUTONOMY_PKEY_PASSWORD, ""),
}
return agent_vars

Expand Down
4 changes: 3 additions & 1 deletion autonomy/deploy/generators/docker_compose/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ipaddress
import os
from pathlib import Path
from string import Template
from typing import Dict, List, Optional, Set, cast

import yaml
Expand Down Expand Up @@ -77,6 +78,7 @@

DEFAULT_PACKAGES_PATH = Path.cwd().absolute() / "packages"
DEFAULT_OPEN_AEA_DIR: Path = Path.home().absolute() / "open-aea"
AGENT_ENV_TEMPLATE = Template("agent_${node_id}.env")


def get_docker_client() -> DockerClient:
Expand Down Expand Up @@ -136,7 +138,7 @@ def to_env_file(agent_vars: Dict, node_id: int, build_dir: Path) -> None:
"""Create a env file under the `agent_build` folder."""
agent_vars["PYTHONHASHSEED"] = 0
agent_vars["LOG_FILE"] = f"/logs/aea_{node_id}.txt"
env_file_path = build_dir / f"agent_{node_id}.env"
env_file_path = build_dir / AGENT_ENV_TEMPLATE.substitute(node_id=node_id)
with open(env_file_path, "w", encoding=DEFAULT_ENCODING) as env_file:
for key, value in agent_vars.items():
env_file.write(f"{key}={value}\n")
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2023 Valory AG
# Copyright 2021-2025 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,7 @@
CUR_PATH = os.path.dirname(inspect.getfile(inspect.currentframe())) # type: ignore
ROOT_DIR = Path(CUR_PATH, "..").resolve().absolute()
DATA_DIR = ROOT_DIR / "tests" / "data"
PACKAGES_DIR = ROOT_DIR / "packages"

skip_docker_tests = pytest.mark.skipif(
platform.system() != "Linux",
Expand Down
37 changes: 23 additions & 14 deletions tests/test_autonomy/test_cli/test_analyse/test_specs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2022-2024 Valory AG
# Copyright 2022-2025 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,9 @@
from unittest import mock

import pytest
import yaml
from aea.cli.registry.settings import REGISTRY_LOCAL
from aea.cli.utils.constants import CLI_CONFIG_PATH, DEFAULT_CLI_CONFIG
from aea.configurations.constants import PACKAGES
from jsonschema.exceptions import ValidationError

Expand Down Expand Up @@ -208,6 +211,18 @@ def setup(self) -> None:

self.specification_path = self.t / self.skill_path / "fsm_specification.yaml"
os.chdir(self.t)
DEFAULT_CLI_CONFIG["registry_config"]["settings"][REGISTRY_LOCAL][
"default_packages_path"
] = (self.t / PACKAGES).as_posix()
Path(CLI_CONFIG_PATH).write_text(yaml.dump(DEFAULT_CLI_CONFIG))

def teardown(self) -> None:
"""Teardown class."""
super().teardown()
DEFAULT_CLI_CONFIG["registry_config"]["settings"][REGISTRY_LOCAL][
"default_packages_path"
] = None
Path(CLI_CONFIG_PATH).write_text(yaml.dump(DEFAULT_CLI_CONFIG))

def _corrupt_spec_file(
self,
Expand Down Expand Up @@ -244,19 +259,19 @@ def test_one_fail(
in stderr
)

def test_check_all(
def test_analyse_fsm_specs(
self,
) -> None:
"""Test --check-all flag."""
"""Test the `analyse fsm-specs` command."""
return_code, stdout, stderr = self.run_cli_subprocess(())

assert return_code == 0, stderr
assert "Done" in stdout

def test_check_all_when_packages_is_not_in_working_dir(
def test_analyse_fsm_specs_when_packages_is_not_in_working_dir(
self,
) -> None:
"""Test --check-all flag when the packages directory is not in the working directory."""
"""Test `analyse fsm-specs` command when the packages directory is not in the working directory."""
return_code, stdout, stderr = self.run_cli_subprocess(())

assert return_code == 0
Expand All @@ -266,7 +281,7 @@ def test_check_all_when_packages_is_not_in_working_dir(
def test_check_fail_when_packages_dir_is_not_named_packages(
self,
) -> None:
"""Test --check-all flag when the packages directory is not named 'packages'."""
"""Test `analyse fsm-specs` command when the packages directory is not named 'packages'."""
wrong_dir = self.t / "some-directory"
wrong_dir.mkdir(exist_ok=True)

Expand All @@ -281,22 +296,16 @@ def test_check_fail_when_packages_dir_is_not_named_packages(
assert return_code == 1, stderr
assert f"packages directory {wrong_dir} is not named '{PACKAGES}'" in stderr

def test_check_all_fail(
def test_analyse_fsm_specs_fail(
self,
) -> None:
"""Test --check-all flag."""
"""Test `analyse fsm-specs` command failure."""
self._corrupt_spec_file()
return_code, stdout, stderr = self.run_cli_subprocess(())

assert return_code == 1
assert "Specifications check for following packages failed" in stderr

def teardown(
self,
) -> None:
"""Tear down the test."""
super().teardown()


class TestDFA:
"""Test the DFA class."""
Expand Down
Loading

0 comments on commit 6b0c444

Please sign in to comment.