Ejemplo n.º 1
0
    def test_shifts_with_some_values(self, i: PythonValue,
                                     j: Optional[int]) -> None:
        TypeCheckLogger.clean_sing()

        new_val1 = i.lshift(pv.int(j))
        new_val2 = i.rshift(pv.int(j))

        assert not i.is_top()
        assert isinstance(i.val, AbstractValue)
        assert isinstance(new_val1.val, AbstractValue)
        assert isinstance(new_val2.val, AbstractValue)

        if i.val.is_top() or j is None:
            assert new_val1.val.is_top()
            assert new_val2.val.is_top()
            assert len(TypeCheckLogger().warnings) == 0
            return

        if new_val1.val.is_top():
            with raises(ValueError):
                ops.lshift(i.val.val, j)  # type: ignore
            assert len(TypeCheckLogger().warnings) > 0
            assert valueError.match(TypeCheckLogger().warnings[0][1])
        else:
            assert ops.lshift(i.val.val, j) == new_val1.val.val  # type: ignore

        if new_val2.val.is_top():
            with raises(ValueError):
                ops.rshift(i.val.val, j)  # type: ignore
            assert len(TypeCheckLogger().warnings) > 0
            assert valueError.match(TypeCheckLogger().warnings[-1][1])
        else:
            assert ops.rshift(i.val.val, j) == new_val2.val.val  # type: ignore
Ejemplo n.º 2
0
    def test_join_to_top_is_always_top(self, val: PythonValue) -> None:
        top = PythonValue.top()
        joined1 = top.join(val)
        joined2 = val.join(top)

        assert joined1.is_top()
        assert joined2.is_top()
        assert joined1 == joined2
Ejemplo n.º 3
0
    def test_join_between_same_types_results_in_same_value(
            self, val1: PythonValue, val2: PythonValue) -> None:
        joined1 = val1.join(val2)
        joined2 = val2.join(val1)

        if val1.is_top() or val2.is_top():
            assert joined1.is_top()
            assert joined2.is_top()
        else:
            assert joined1.is_top() != isinstance(val1.val, type(val2.val))
            assert joined2.is_top() != isinstance(val1.val, type(val2.val))

        assert joined1 == joined2
Ejemplo n.º 4
0
    def test_running_if_with_booltop_is_the_same_as_joining_noelse(
            self, i: PythonValue, j: PythonValue) -> None:
        """
        This test simulates the transformation of the following piece of code:

        > b = 2
        > if d:
        >    b = 5
        """

        st = pt.Store()

        st['b'] = i

        def if_(st):
            # type: (Store) -> Store
            st['b'] = j
            return st

        if_qst = st['d']

        st = pt.runIf(st, if_qst, if_)

        val_b = st['b']

        assert val_b == i.join(j)
Ejemplo n.º 5
0
 def test_anything_operated_with_top_is_top(self, val: PythonValue) -> None:
     for op in ops_symbols.keys():
         top = PythonValue.top()
         new_val = getattr(val, op)(top)
         assert new_val.is_top()
         new_val = getattr(top, op)(val)
         assert new_val.is_top()
Ejemplo n.º 6
0
from pytropos.internals.values.builtin_values import *
from pytropos.internals.values.python_values import PythonValue as PV

exitcode = 1

store = {
    'n': PV.top(),
    'i': PV(Int.top()),
    'j': PV(Int.top()),
}
Ejemplo n.º 7
0
import pytropos.internals.values as pv
from pytropos.internals.values.builtin_values import *
from pytropos.internals.values.python_values.builtin_mutvalues import *
from pytropos.internals.values.python_values import PythonValue as PV

exitcode = 1

store = {
    '_': PV.top(),
    'a': PV(List([pv.list([PV(Int.top())]), PV.top()], size=(1, 2))),
    'b': PV(Int.top()),
    'c': PV(List([PV.top(), PV.top()])),
}
store['c'].val.children[('index', 1)] = store['a']
# similar to c[1] = a
Ejemplo n.º 8
0
from pytropos.internals.values.builtin_values import *
from pytropos.internals.values.python_values import PythonValue as PV

exitcode = 1

store = {'a': PV(Int(5)), 'c': PV.top(), 'd': PV.top()}
Ejemplo n.º 9
0
import pytropos.internals.values as pv
from pytropos.internals.values.python_values import PythonValue as PV

exitcode = 1

store = {
    'a': PV.top(),
    'l': pv.list([PV.top(), pv.int(21), PV.top()]),
    'n': PV.top(),
    'm': PV.top(),
}
Ejemplo n.º 10
0
from pytropos.internals.values.builtin_values import *
from pytropos.internals.values.python_values import PythonValue as PV

exitcode = 1

store = {
    'i': PV(Int(10)),
    'j': PV.top(),
}
Ejemplo n.º 11
0
from pytropos.internals.values.builtin_values import *
from pytropos.internals.values.python_values.builtin_mutvalues import *
from pytropos.internals.values.python_values import PythonValue

exitcode = 1

store = {
    'a': PythonValue(
        List([PythonValue(Int(2)), PythonValue(Int(6))], size=(2, 2))),
    'dd': PythonValue(NoneType())
}
Ejemplo n.º 12
0
 def test_bool_returns_always_a_Bool(self, val: PythonValue) -> None:
     TypeCheckLogger.clean_sing()
     bool_val = val.bool()
     assert isinstance(bool_val.val, Bool)
     assert len(TypeCheckLogger().warnings) == 0
Ejemplo n.º 13
0
import hypothesis.strategies as st

import pytropos.internals.values as pv
from pytropos.internals.values.python_values import PythonValue

st_ints = st.one_of(st.integers(), st.none())
st_floats = st.one_of(st.floats(), st.none())
st_bools = st.one_of(st.booleans(), st.none())

st_pv_bools_ints = st.one_of(
    st.builds(pv.int, st_ints),
    st.builds(pv.bool, st_bools),
)

st_any_pv = st.one_of(st.builds(pv.int, st_ints),
                      st.builds(pv.float, st_floats),
                      st.builds(pv.bool, st_bools), st.just(pv.none()),
                      st.just(PythonValue.top()))
Ejemplo n.º 14
0
from pytropos.internals.values.builtin_values import *
from pytropos.internals.values.python_values import PythonValue as PV

exitcode = 1

store = {
    'a': PV(Int(5)),
    'c': PV(Float(2)),
    'd': PV.top()
}
Ejemplo n.º 15
0
from pytropos.internals.values.builtin_values import *
from pytropos.internals.values.python_values import PythonValue as PV

exitcode = 1

store = {
    '_': PV.top(),
    'c': PV.top(),
    'b': PV.top(),
    'a': PV.top(),
}