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)
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)
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)
def test_any_empty_set_success(): from tmppy import empty_set assert any(empty_set(bool)) == False
def test_all_empty_set_success(): from tmppy import empty_set assert all(empty_set(bool)) == True
def test_sum_empty_set_success(): from tmppy import empty_set assert sum(empty_set(int)) == 0
def f(x: bool): return empty_set(bool, x=x) # error: Keyword arguments are not supported.
def f(x: bool): return empty_set(1) # error: Unsupported type declaration.
def test_empty_set_success(): from tmppy import empty_set assert empty_set(bool) == empty_set(bool)
def f(x: bool): return empty_set(bool, bool) # error: empty_set\(\) takes 1 argument. Got: 2
def test_type_set_in_empty(): from tmppy import Type, empty_set assert not (Type('int') in empty_set(Type))
def test_int_set_in_empty(): from tmppy import empty_set assert not (1 in empty_set(int))
def test_bool_set_in_empty(): from tmppy import empty_set assert not (False in empty_set(bool))
# 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)