import pytest from phasm.type5.solver import Type5SolverException from ..helpers import Suite @pytest.mark.integration_test def test_imported_ok(): code_py = """ @imported def helper(mul: i32) -> i32: pass @exported def testEntry() -> i32: return helper(2) """ def helper(mul: int) -> int: return 4238 * mul result = Suite(code_py).run_code( imports={ 'helper': helper, } ) assert 8476 == result.returned_value @pytest.mark.integration_test def test_imported_side_effect_no_return(): code_py = """ @imported def helper(mul: u8) -> None: pass @exported def testEntry() -> None: return helper(3) """ prop = None def helper(mul: int) -> None: nonlocal prop prop = mul result = Suite(code_py).run_code( imports={ 'helper': helper, } ) assert None is result.returned_value assert 3 == prop @pytest.mark.integration_test def test_imported_type_mismatch(): code_py = """ @imported def helper(mul: u8) -> u8: pass @exported def testEntry(x: u32) -> u8: return helper(x) """ def helper(mul: int) -> int: return 4238 * mul with pytest.raises(Type5SolverException, match='Not the same type'): Suite(code_py).run_code( imports={ 'helper': helper, } )