示例#1
0
def test_set_comprehension_from_int_set_throws_toplevel():
    from tmppy import empty_set

    class MyError(Exception):
        def __init__(self, b: bool):
            self.message = 'Something went wrong'
            self.b = b

    def f(n: int):
        if n == 1:
            raise MyError(True)
        return True

    assert {f(x) for x in {0, 1, 2}} == empty_set(bool)
示例#2
0
def test_set_comprehension_from_type_set_throws_toplevel():
    from tmppy import empty_set, Type

    class MyError(Exception):
        def __init__(self, b: bool):
            self.message = 'Something went wrong'
            self.b = b

    def f(x: Type):
        if x == Type('float'):
            raise MyError(True)
        return True

    assert {f(x)
            for x in {Type('int'), Type('float'),
                      Type('double')}} == empty_set(bool)
示例#3
0
def test_set_comprehension_from_custom_type_set_throws_toplevel():
    from tmppy import empty_set

    class Int:
        def __init__(self, n: int):
            self.n = n

    class MyError(Exception):
        def __init__(self, b: bool):
            self.message = 'Something went wrong'
            self.b = b

    def f(x: Int):
        if x == Int(1):
            raise MyError(True)
        return True

    assert {f(x) for x in {Int(0), Int(1), Int(2)}} == empty_set(bool)
示例#4
0
def test_any_empty_set_success():
    from tmppy import empty_set
    assert any(empty_set(bool)) == False
示例#5
0
def test_all_empty_set_success():
    from tmppy import empty_set
    assert all(empty_set(bool)) == True
示例#6
0
def test_sum_empty_set_success():
    from tmppy import empty_set
    assert sum(empty_set(int)) == 0
示例#7
0
 def f(x: bool):
     return empty_set(bool,
                      x=x)  # error: Keyword arguments are not supported.
示例#8
0
 def f(x: bool):
     return empty_set(1)  # error: Unsupported type declaration.
示例#9
0
def test_empty_set_success():
    from tmppy import empty_set
    assert empty_set(bool) == empty_set(bool)
示例#10
0
 def f(x: bool):
     return empty_set(bool,
                      bool)  # error: empty_set\(\) takes 1 argument. Got: 2
示例#11
0
def test_type_set_in_empty():
    from tmppy import Type, empty_set
    assert not (Type('int') in empty_set(Type))
示例#12
0
def test_int_set_in_empty():
    from tmppy import empty_set
    assert not (1 in empty_set(int))
示例#13
0
def test_bool_set_in_empty():
    from tmppy import empty_set
    assert not (False in empty_set(bool))
示例#14
0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from tmppy import empty_set, Type


class MyError(Exception):
    def __init__(self, b: bool):
        self.message = 'Something went wrong'
        self.b = b


def f(x: Type):
    if x == Type('float'):
        raise MyError(True)
    return True


assert {f(x)
        for x in {Type('int'), Type('float'),
                  Type('double')}} == empty_set(bool)