Пример #1
0
 def test_none_affects_everything(self, i: Optional[int],
                                  j: Optional[float]) -> None:
     for op in ['add', 'sub', 'mul']:
         res = getattr(pv.int(i), op)(pv.float(j)).val.is_top()
         res2 = getattr(pv.float(j), op)(pv.int(i)).val.is_top()
         is_i_or_j_none = (i is None) or (j is None)
         assert (is_i_or_j_none == res == res2)
Пример #2
0
    def test_float_and_ints_comform_to_baseline_python_divs(
            self, i: int, j: float) -> None:
        for op in ['truediv', 'floordiv', 'mod']:
            TypeCheckLogger.clean_sing()

            if j == 0.0:
                with raises(ZeroDivisionError):
                    getattr(ops, op)(i, j)
                newval = getattr(pv.int(i), op)(pv.float(j))
                assert isinstance(newval.val, (Int, Float))
                assert newval.val.is_top()

                assert len(TypeCheckLogger().warnings) == 1
                assert zeroDivisionError.match(
                    TypeCheckLogger().warnings[0][1])
            else:
                assert check_float_equality(
                    getattr(ops, op)(i, j),
                    getattr(pv.int(i), op)(pv.float(j)).val.val)
                assert len(TypeCheckLogger().warnings) == 0

            if i == 0:
                with raises(ZeroDivisionError):
                    getattr(ops, op)(j, i)
                newval = getattr(pv.float(j), op)(pv.int(i))
                assert isinstance(newval.val, (Int, Float))
                assert newval.val.is_top()

                assert len(TypeCheckLogger().warnings) > 0
                assert zeroDivisionError.match(
                    TypeCheckLogger().warnings[-1][1])
            else:
                assert check_float_equality(
                    getattr(ops, op)(j, i),
                    getattr(pv.float(j), op)(pv.int(i)).val.val)
Пример #3
0
 def test_error_pos_is_correctly_passed_to_warning(
         self, src_pos: 'Optional[Pos]') -> None:
     for op in ['truediv', 'floordiv', 'mod']:
         TypeCheckLogger.clean_sing()
         getattr(pv.float(1.0), op)(pv.float(0.0), src_pos)
         assert len(TypeCheckLogger().warnings) == 1
         assert TypeCheckLogger().warnings[-1][2] == src_pos
Пример #4
0
 def test_float_and_ints_comform_to_baseline_python(self, i: int,
                                                    j: float) -> None:
     for op in ['add', 'sub', 'mul']:
         op_fun = getattr(ops, op)
         assert check_float_equality(
             op_fun(i, j),
             getattr(pv.int(i), op)(pv.float(j)).val.val)
         assert check_float_equality(
             op_fun(j, i),
             getattr(pv.float(j), op)(pv.int(i)).val.val)
Пример #5
0
    def test_op_float(self, i: float, j: float) -> None:
        """
        This test basically checks that doing something like this:
        Float(3) + Float(5) == Float(8)
        for all operations (+*/...) and Values
        """
        for op in ['add', 'sub', 'mul', 'truediv', 'floordiv', 'mod']:
            TypeCheckLogger.clean_sing()

            pt_val = getattr(pv.float(i), op)(pv.float(j))
            assert isinstance(pt_val.val, Float)
            if pt_val.val.is_top():
                with raises(ZeroDivisionError):
                    getattr(ops, op)(i, j)
                assert len(TypeCheckLogger().warnings) == 1
                assert zeroDivisionError.match(
                    TypeCheckLogger().warnings[0][1])
            else:
                assert check_float_equality(
                    getattr(ops, op)(i, j), pt_val.val.val)  # type: ignore
                assert len(TypeCheckLogger().warnings) == 0
Пример #6
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.wrappers import *
from pytropos.internals.values.python_values.python_values import PythonValue, PT

exitcode = 1

b_ = pv.list([pv.float(5.0), pv.none()])
a = pv.list([pv.int(9), b_])
b_.val.children['index', 1] = a

store = {
    'a': a,
    'b': a.val.get_attrs()['append'],
    'c': b_.val.get_attrs()['append'],
}
Пример #7
0
 def test_float_from_operating_int_with_float(self, i: Optional[int],
                                              j: Optional[float]) -> None:
     for op in ['add', 'sub', 'mul', 'truediv', 'floordiv', 'mod']:
         assert isinstance(getattr(pv.int(i), op)(pv.float(j)).val, Float)
         assert isinstance(getattr(pv.float(j), op)(pv.int(i)).val, Float)
Пример #8
0
 def test_float_preserved(self, i: float) -> None:
     new_val = pv.float(i)
     assert not new_val.val.is_top()  # type: ignore
     assert check_float_equality(i, new_val.val.val)  # type: ignore
Пример #9
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.wrappers import *
from pytropos.internals.values.python_values.python_values import PythonValue, PT

exitcode = 1

store = {
    'a': pv.list([pv.int(2), pv.float(3.0),
                  pv.tuple()]),
}