Skip to content

Commit

Permalink
test: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 19, 2024
1 parent 552b739 commit e1eb258
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
18 changes: 17 additions & 1 deletion tests/functional/test_project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import shutil
from pathlib import Path

Expand All @@ -12,7 +13,7 @@
from ape import Project
from ape.api.projects import ApeProject
from ape.contracts import ContractContainer
from ape.exceptions import ProjectError
from ape.exceptions import ProjectError, ConfigError
from ape.logging import LogLevel
from ape.utils import create_tempdir
from ape_pm import BrownieProject, FoundryProject
Expand Down Expand Up @@ -666,6 +667,21 @@ def test_init(self, with_dependencies_project_path):
# Manifest should have been created by default.
assert not project.manifest_path.is_file()

def test_init_invalid_config(self):
here = os.curdir
with create_tempdir() as temp_dir:
cfgfile = temp_dir / "ape-config.yaml"
# Name is invalid!
cfgfile.write_text("name:\n {asdf}")

os.chdir(temp_dir)
expected = r"[.\n]*Input should be a valid string\n-->1: name:\n 2: {asdf}[.\n]*"
try:
with pytest.raises(ConfigError, match=expected):
_ = Project(temp_dir)
finally:
os.chdir(here)

def test_config_override(self, with_dependencies_project_path):
contracts_folder = with_dependencies_project_path / "my_contracts"
config = {"contracts_folder": contracts_folder.name}
Expand Down
24 changes: 1 addition & 23 deletions tests/integration/cli/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from ape import Project
from ape.utils import create_tempdir
from tests.conftest import ApeSubprocessRunner
from tests.integration.cli.utils import run_once

Expand Down Expand Up @@ -33,26 +34,3 @@ def test_help(ape_cli, runner):
rf"test\s*Launches pytest{anything}"
)
assert re.match(expected.strip(), result.output)


@run_once
def test_invalid_config():
# Using subprocess runner so we re-hit the init of the cmd.
runner = ApeSubprocessRunner("ape")
here = os.curdir
with Project.create_temporary_project() as tmp:
cfgfile = tmp.path / "ape-config.yaml"
# Name is invalid!
cfgfile.write_text("name:\n {asdf}")

os.chdir(tmp.path)
result = runner.invoke("--help")
os.chdir(here)

expected = """
Input should be a valid string
-->1: name:
2: {asdf}
""".strip()
assert result.exit_code != 0
assert expected in result.output

0 comments on commit e1eb258

Please sign in to comment.