Exemplo n.º 1
0
 def test_multiline_strings(self):
     tester('a')
     tester('''
         ab''')
     tester('''
                 abc
                 def
                 ''')
     str([
         tester('''
             123
             456
             '''),
         tester('''
             345
             456786
             '''),
     ])
     tester([
         '''
             123
             456
             '''
         '''
             345
             456786
             ''', '''
             123
             456
             ''', '''
             345
             456786
             '''
     ])
Exemplo n.º 2
0
    def test_generator(self):
        def gen():
            for x in [1, 2]:
                yield tester(x)

        gen2 = (tester(x) for x in tester([1, 2]))

        assert list(gen()) == list(gen2) == [1, 2]
Exemplo n.º 3
0
def test_pytest():
    from tests.utils import tester

    lst = [1, 2, 3]
    lst2 = tester(lst)
    assert lst == lst2
    lst3 = tester(lst + [4])
    assert ([1, 2, 3, 4] == lst3), 'message'
    x = tester.x
    assert x is tester
Exemplo n.º 4
0
 def test_decorator(self):
     @empty_decorator
     @decorator_with_args(tester('123'), x=int())
     @tester(list(tuple([1, 2])), returns=empty_decorator)
     @tester(list(tuple([3, 4])), returns=empty_decorator)
     @empty_decorator
     @decorator_with_args(str(), x=int())
     @tester(list(tuple([5, 6])), returns=empty_decorator)
     @tester(list(tuple([7, 8])), returns=empty_decorator)
     @empty_decorator
     @decorator_with_args(tester('sdf'), x=tester('123234'))
     def foo():
         pass
Exemplo n.º 5
0
 def test_comprehensions(self):
     # Comprehensions can be separated if they contain different names
     str([{tester(x) for x in [1]}, {tester(y) for y in [1]}])
     # or are on different lines
     str([{tester(x) for x in [1]}, {tester(x) for x in [1]}])
     # or are of different types
     str([{tester(x) for x in [1]}, list(tester(x) for x in [1])])
     # but not if everything is the same
     # noinspection PyTypeChecker
     with self.assertRaises(NotOneValueFound):
         str([{tester(x) for x in [1]}, {tester(x) for x in [2]}])
Exemplo n.º 6
0
    def test_closures_and_nested_comprehensions(self):
        x = 1
        # @formatter:off
        str({tester(a+x): {tester(b+x): {tester(c+x) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})

        def foo():
            y = 2
            str({tester(a+x): {tester(b+x): {tester(c+x) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
            str({tester(a+y): {tester(b+y): {tester(c+y) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
            str({tester(a+x+y): {tester(b+x+y): {tester(c+x+y) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})

            def bar():
                z = 3
                str({tester(a+x): {tester(b+x): {tester(c+x) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
                str({tester(a+y): {tester(b+y): {tester(c+y) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
                str({tester(a+x+y): {tester(b+x+y): {tester(c+x+y) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
                str({tester(a+x+y+z): {tester(b+x+y+z): {tester(c+x+y+z) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})

            bar()

        foo()
Exemplo n.º 7
0
 def test_lambda(self):
     self.assertEqual(
         (lambda x: (tester(x), tester(x)))(tester(3)),
         (3, 3),
     )
     (lambda: (lambda: tester(1))())()
     self.assertEqual(
         (lambda: [tester(x) for x in tester([1, 2])])(),
         [1, 2],
     )
Exemplo n.º 8
0
 def test_semicolons(self):
     # @formatter:off
     tester(1); tester(2); tester(3)
     tester(9
            ); tester(
         8); tester(
         99
     ); tester(33); tester([4,
                            5, 6, [
                             7]])
Exemplo n.º 9
0
 def test_multiple_statements_on_one_line(self):
     if tester(1): tester(2)
     for _ in tester([1, 2]): tester(3)
Exemplo n.º 10
0
 def test_future_import(self):
     print(1 / 2)
     tester(4)
Exemplo n.º 11
0
 def gen():
     for x in [1, 2]:
         yield tester(x)
Exemplo n.º 12
0
            func.x = x
            return func

        return decorator

    @assign(lambda: 1)
    def foo():
        return lambda: lambda: 3

    return foo


lamb = lambda: 0


assert tester([1, 2, 3]) == [1, 2, 3]

assert tester.asd is tester
assert tester[1 + 2] is tester
assert tester ** 4 is tester
assert tester * 3 is tester
assert tester - 2 is tester
assert tester + 1 is tester
assert -tester is +tester is ~tester is tester
assert (tester < 7) is tester
assert (tester >= 78) is tester
assert (tester != 79) is tester
# assert (5 != tester != 6) is tester
assert tester.foo(45, False) == 45

assert (tester or 234) == 234
Exemplo n.º 13
0
 class foo3(tester("5") and list):
     pass
Exemplo n.º 14
0
 def foo2(_=tester("3"), __=tester("4")):
     pass
Exemplo n.º 15
0
    def test_decorator(self):
        @empty_decorator  # 0
        @decorator_with_args(tester('123'), x=int())  # 1
        @tester(list(tuple([1, 2])))  # 2!
        @tester(  # 3!
            list(
                tuple(
                    [3, 4])),
            )
        @empty_decorator  # 4
        @decorator_with_args(  # 5
            str(),
            x=int())
        @tester(list(tuple([5, 6])))  # 6!
        @tester(list(tuple([7, 8])))  # 7!
        @empty_decorator
        @decorator_with_args(tester('sdf'), x=tester('123234'))
        def foo():
            pass

        tester.check_decorators([7, 6, 3, 2])

        empty_decorator.tester = tester

        @empty_decorator
        @tester
        @empty_decorator
        @tester.qwe
        @empty_decorator
        @tester("1")
        @empty_decorator.tester("2")
        @empty_decorator
        def foo2(_=tester("3"), __=tester("4")):
            pass

        tester.check_decorators([6, 5, 3, 1])

        @tester
        @empty_decorator
        @tester.qwe
        @empty_decorator
        @tester("11")
        @empty_decorator.tester("22")
        @empty_decorator
        class foo3(tester("5") and list):
            pass

        tester.check_decorators([5, 4, 2, 0])

        class Foo(object):
            @tester
            @tester
            @empty_decorator
            @tester.qwe
            @empty_decorator
            def foo(self):
                super(Foo, self)

                class Bar:
                    @tester
                    @empty_decorator
                    @tester.qwe
                    @empty_decorator
                    def bar(self):
                        pass

        Foo().foo()
        tester.check_decorators([3, 1, 0, 2, 0])
Exemplo n.º 16
0
 def bar():
     z = 3
     str({tester(a+x): {tester(b+x): {tester(c+x) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
     str({tester(a+y): {tester(b+y): {tester(c+y) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
     str({tester(a+x+y): {tester(b+x+y): {tester(c+x+y) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
     str({tester(a+x+y+z): {tester(b+x+y+z): {tester(c+x+y+z) for c in tester([1, 2])} for b in tester([3, 4])} for a in tester([5, 6])})
Exemplo n.º 17
0
    def test_compound_statements(self):
        with self.assertRaises(TypeError):
            try:
                for _ in tester([1, 2, 3]):
                    while tester(0):
                        pass
                    else:
                        tester(4)
                else:
                    tester(5)
                    raise ValueError
            except tester(ValueError):
                tester(9)
                raise TypeError
            finally:
                tester(10)

        # PyCharm getting confused somehow?
        # noinspection PyUnreachableCode
        str()

        with self.assertRaises(tester(Exception)):
            if tester(0):
                pass
            elif tester(0):
                pass
            elif tester(1 / 0):
                pass