Skip to content

Commit

Permalink
add tests for initializer hints
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberthirst committed Apr 5, 2024
1 parent ab1a2e3 commit 713007e
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/functional/syntax/modules/test_initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,3 +1228,67 @@ def use_lib1():
compile_code(main, input_bundle=input_bundle, output_formats=["annotated_ast_dict"])
is not None
)


def test_hint_for_missing_initializer_in_list(make_input_bundle):
lib1 = """
counter: uint256
"""
lib3 = """
counter: uint256
"""
lib2 = """
import lib1
import lib3
uses: lib1
uses: lib3
counter: uint256
@internal
def foo():
lib1.counter += 1
lib3.counter += 1
"""
main = """
import lib1
import lib2
import lib3
initializes: lib2[lib1:=lib1]
initializes: lib1
initializes: lib3
"""
input_bundle = make_input_bundle({"lib1.vy": lib1, "lib2.vy": lib2, "lib3.vy": lib3})
with pytest.raises(InitializerException) as e:
compile_code(main, input_bundle=input_bundle)
assert e.value._message == "`lib2` uses `lib3`, but it is not initialized with `lib3`"
assert e.value._hint == "add `lib3 := lib3` to its initializer list"


def test_hint_for_missing_initializer_when_no_import(make_input_bundle):
lib1 = """
counter: uint256
"""
lib2 = """
import lib1
uses: lib1
counter: uint256
@internal
def foo():
lib1.counter += 1
"""
main = """
import lib2
initializes: lib2
"""
input_bundle = make_input_bundle({"lib1.vy": lib1, "lib2.vy": lib2})
with pytest.raises(InitializerException) as e:
compile_code(main, input_bundle=input_bundle)
assert e.value._message == "`lib2` uses `lib1`, but it is not initialized with `lib1`"
assert e.value._hint == "try importing lib1 first"

0 comments on commit 713007e

Please sign in to comment.