Skip to content

Commit

Permalink
use pytest.raises instead of assert_compile_failed
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Dec 27, 2023
1 parent 81d1bfb commit 3736bf5
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 53 deletions.
4 changes: 2 additions & 2 deletions tests/functional/syntax/exceptions/test_argument_exception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import ArgumentException

fail_list = [
Expand Down Expand Up @@ -95,4 +95,4 @@ def foo():
@pytest.mark.parametrize("bad_code", fail_list)
def test_function_declaration_exception(bad_code):
with pytest.raises(ArgumentException):
compiler.compile_code(bad_code)
compile_code(bad_code)
9 changes: 5 additions & 4 deletions tests/functional/syntax/test_abs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
Expand All @@ -18,8 +18,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_abs_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_abs_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand All @@ -36,4 +37,4 @@ def foo():

@pytest.mark.parametrize("code", valid_list)
def test_abs_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
4 changes: 2 additions & 2 deletions tests/functional/syntax/test_addmulmod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
Expand Down Expand Up @@ -46,4 +46,4 @@ def test_add_mod_fail(assert_compile_failed, get_contract, code, exc):

@pytest.mark.parametrize("code", valid_list)
def test_addmulmod_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
6 changes: 4 additions & 2 deletions tests/functional/syntax/test_as_wei_value.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from vyper import compile_code
from vyper.exceptions import (
ArgumentException,
InvalidLiteral,
Expand Down Expand Up @@ -84,8 +85,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_as_wei_fail(get_contract_with_gas_estimation, bad_code, exc, assert_compile_failed):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_as_wei_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_ceil.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper.compiler import compile_code
from vyper import compile_code

valid_list = [
"""
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/syntax/test_dynamic_array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import StructureException

fail_list = [
Expand Down Expand Up @@ -36,8 +36,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_block_fail(assert_compile_failed, get_contract, bad_code, exc):
assert_compile_failed(lambda: get_contract(bad_code), exc)
def test_block_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand All @@ -56,4 +57,4 @@ def test_block_fail(assert_compile_failed, get_contract, bad_code, exc):

@pytest.mark.parametrize("good_code", valid_list)
def test_dynarray_pass(good_code):
assert compiler.compile_code(good_code) is not None
assert compile_code(good_code) is not None
15 changes: 10 additions & 5 deletions tests/functional/syntax/test_epsilon.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import pytest

from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
"""
(
"""
FOO: constant(address) = epsilon(address)
"""
""",
InvalidType,
)
]


@pytest.mark.parametrize("bad_code", fail_list)
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), InvalidType)
@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_block_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_floor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper.compiler import compile_code
from vyper import compile_code

valid_list = [
"""
Expand Down
13 changes: 6 additions & 7 deletions tests/functional/syntax/test_len.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from pytest import raises

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import TypeMismatch

fail_list = [
Expand All @@ -21,11 +20,11 @@ def foo(inp: int128) -> uint256:
@pytest.mark.parametrize("bad_code", fail_list)
def test_block_fail(bad_code):
if isinstance(bad_code, tuple):
with raises(bad_code[1]):
compiler.compile_code(bad_code[0])
with pytest.raises(bad_code[1]):
compile_code(bad_code[0])
else:
with raises(TypeMismatch):
compiler.compile_code(bad_code)
with pytest.raises(TypeMismatch):
compile_code(bad_code)


valid_list = [
Expand Down Expand Up @@ -53,4 +52,4 @@ def foo() -> uint256:

@pytest.mark.parametrize("good_code", valid_list)
def test_list_success(good_code):
assert compiler.compile_code(good_code) is not None
assert compile_code(good_code) is not None
9 changes: 5 additions & 4 deletions tests/functional/syntax/test_method_id.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidLiteral, InvalidType

fail_list = [
Expand Down Expand Up @@ -28,8 +28,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_method_id_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_method_id_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand All @@ -46,4 +47,4 @@ def foo(a: Bytes[4] = BAR):

@pytest.mark.parametrize("code", valid_list)
def test_method_id_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
9 changes: 5 additions & 4 deletions tests/functional/syntax/test_minmax.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidType, OverflowException, TypeMismatch

fail_list = [
Expand Down Expand Up @@ -32,8 +32,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_block_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand All @@ -60,4 +61,4 @@ def foo():

@pytest.mark.parametrize("good_code", valid_list)
def test_block_success(good_code):
assert compiler.compile_code(good_code) is not None
assert compile_code(good_code) is not None
23 changes: 17 additions & 6 deletions tests/functional/syntax/test_minmax_value.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import pytest

from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
"""
(
"""
@external
def foo():
a: address = min_value(address)
""",
"""
InvalidType,
),
(
"""
@external
def foo():
a: address = max_value(address)
""",
"""
InvalidType,
),
(
"""
FOO: constant(address) = min_value(address)
@external
def foo():
a: address = FOO
""",
InvalidType,
),
]


@pytest.mark.parametrize("bad_code", fail_list)
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), InvalidType)
@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_block_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)
9 changes: 5 additions & 4 deletions tests/functional/syntax/test_powmod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
Expand All @@ -16,8 +16,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_powmod_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_powmod_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand All @@ -35,4 +36,4 @@ def foo():

@pytest.mark.parametrize("code", valid_list)
def test_powmod_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
6 changes: 3 additions & 3 deletions tests/functional/syntax/test_raw_call.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import ArgumentException, InvalidType, SyntaxException, TypeMismatch

fail_list = [
Expand Down Expand Up @@ -39,7 +39,7 @@ def foo():
@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_raw_call_fail(bad_code, exc):
with pytest.raises(exc):
compiler.compile_code(bad_code)
compile_code(bad_code)


valid_list = [
Expand Down Expand Up @@ -109,4 +109,4 @@ def foo():

@pytest.mark.parametrize("good_code", valid_list)
def test_raw_call_success(good_code):
assert compiler.compile_code(good_code) is not None
assert compile_code(good_code) is not None
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_ternary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper.compiler import compile_code
from vyper import compile_code
from vyper.exceptions import InvalidType, TypeMismatch

good_list = [
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/syntax/test_uint2str.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code

valid_list = [
"""
Expand All @@ -16,4 +16,4 @@ def foo():

@pytest.mark.parametrize("code", valid_list)
def test_addmulmod_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_unary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper.compiler import compile_code
from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
Expand Down

0 comments on commit 3736bf5

Please sign in to comment.