Skip to content

Commit

Permalink
test: add CLI test for flattener
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshultz committed Mar 14, 2024
1 parent b63aad7 commit 6810466
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ape
import pytest
import vvm # type: ignore
from click.testing import CliRunner

# NOTE: Ensure that we don't use local paths for these
DATA_FOLDER = Path(mkdtemp()).resolve()
Expand Down Expand Up @@ -211,6 +212,11 @@ def all_versions():
return ALL_VERSIONS


@pytest.fixture
def cli_runner():
return CliRunner()


def _get_tb_contract(version: str, project, account):
registry_type = project.get_contract(f"registry_{version}")
registry = account.deploy(registry_type)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pathlib import Path
from tempfile import NamedTemporaryFile

import pytest

from ape_vyper._cli import cli


@pytest.mark.parametrize(
"contract_name,expected",
[
# This first one has most known edge cases
(
"flatten_me.vy",
[
"from vyper.interfaces import ERC20",
"interface Dep:",
"interface IFace:",
"interface IFaceTwo:",
],
),
],
)
def test_cli_flatten(project, contract_name, expected, cli_runner):
path = project.contracts_folder / contract_name
with NamedTemporaryFile() as tmpfile:
result = cli_runner.invoke(cli, ["flatten", str(path), tmpfile.name])
assert result.exit_code == 0, result.stderr_bytes
output = Path(tmpfile.name).read_text()
for expect in expected:
assert expect in output

0 comments on commit 6810466

Please sign in to comment.