Skip to content

Commit

Permalink
add test to mock sys path
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Feb 12, 2024
1 parent 7887ce9 commit eac2d2f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/unit/cli/vyper_compile/test_compile_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import contextlib
import sys
from pathlib import Path

import pytest
Expand Down Expand Up @@ -257,3 +259,34 @@ def foo() -> uint256:
contract_file = make_file("contract.vy", contract_source)

assert compile_files([contract_file], ["combined_json"], paths=[tmp_path]) is not None


@contextlib.contextmanager
def mock_sys_path(path):
try:
sys.path.append(path)
yield
finally:
sys.path.pop()


def test_import_sys_path(tmp_path_factory, make_file):
library_source = """
@internal
def foo() -> uint256:
return block.number + 1
"""
contract_source = """
import lib
@external
def foo() -> uint256:
return lib.foo()
"""
tmpdir = tmp_path_factory.mktemp("test-sys-path")
with open(tmpdir / "lib.vy", "w") as f:
f.write(library_source)

contract_file = make_file("contract.vy", contract_source)
with mock_sys_path(tmpdir):
assert compile_files([contract_file], ["combined_json"]) is not None

0 comments on commit eac2d2f

Please sign in to comment.