示例#1
0
 def test_dict_unpack(self):
     vector = (given({
         "x": 1,
         "y": 2,
         "z": 3
     })(unpack, lambda x, y, z: (x, y, z)).end)
     self.assertEqual(vector, (1, 2, 3))
示例#2
0
 def test_product_method(self):
     expected = [(i, j) for i in "abc" for j in range(4)]
     result = (given("abc")
                  (product, ANS, range(4))
                  ((i, j) for i, j in ANS)
                  (list)
              .end)
     self.assertEqual(result, expected)
示例#3
0
    def test_pallete_bug(self):
        def rgb_to_hex(color):
            return '#%02x%02x%02x' % color

        s_c = 5
        color_count = s_c + 2
        grays = (given(color_count)(range)(
            round(255 / (s_c + 1) * c)
            for c in ANS)(rgb_to_hex((b, b, b))
                          for b in ANS)(list)(reversed)).end
示例#4
0
 def test_method_binding(self):
     result = (
         given("abcdefghi")
         .upper()
         .replace("E", " ")
         (c.lower() for c in ANS)
         (list)
         ("".join)
     ).end
     self.assertEqual(result, "abcd fghi")
示例#5
0
    def test_pallete_bug(self):

        def rgb_to_hex(color):
            return '#%02x%02x%02x' % color

        s_c = 5
        color_count = s_c + 2
        grays = (
            given(color_count)
            (range)
            (round(255/(s_c + 1)*c) for c in ANS)
            (rgb_to_hex((b, b, b)) for b in ANS)
            (list)
            (reversed)
        ).end
示例#6
0
 def test_two_functions(self):
     result = given(15)(lambda x: x + 15)(str).end
     self.assertEqual(result, "30")
示例#7
0
 def test_not_callable_attribute(self):
     message = "'int' object is not callable"
     with self.assertRaisesRegex(TypeError, message):
         given(1).imag()
示例#8
0
 def test_unpack_false(self):
     vector = (given([1, 2])(unpack,
                             lambda x, y: [x, y])(lambda x: x * 2).end)
     self.assertEqual(vector, [1, 2, 1, 2])
示例#9
0
 def test_many_for_statements(self):
     description = R"Multiple for statement are not allowed."
     with self.assertRaisesRegex(SyntaxError, description):
         given([1, 2, 3])(i*j for i in range(3) for j in ANS).end
示例#10
0
 def test_many_explicit_keyword_arguments(self):
     result = given("z")(lambda x, y, z: x + y + z, x=ANS, y=ANS, z=ANS).end
     self.assertEqual(result, "zzz")
示例#11
0
 def test_explicit_positinonal_argument(self):
     result = given(9)(lambda x, y: x / y, 0, ANS).end
     self.assertEqual(result, 0)
示例#12
0
 def test_positional_arguments(self):
     result = given("a.c")(str.replace, ".", "b").end
     self.assertEqual(result, "abc")
示例#13
0
 def test_two_functions(self):
     result = given(15)(lambda x: x + 15)(str).end
     self.assertEqual(result, "30")
示例#14
0
 def test_single_function(self):
     result = given(15)(lambda x: x + 15).end
     self.assertEqual(result, 30)
示例#15
0
 def test_first_argument(self):
     description = R"Expected 'callable' or 'generator'. Got 'int'"
     with self.assertRaisesRegex(TypeError, description):
         given(9)(8).end
示例#16
0
 def test_not_callable_attribute(self):
     message = "'int' object is not callable"
     with self.assertRaisesRegex(TypeError, message):
         given(1).imag()
示例#17
0
 def test_explicit_positinonal_argument(self):
     result = given(9)(lambda x, y: x/y, 0, ANS).end
     self.assertEqual(result, 0)
示例#18
0
 def test_many_explicit_positinonal_argument(self):
     result = given(9)(lambda x, y, z: x * y * z, ANS, ANS, ANS).end
     self.assertEqual(result, 729)
示例#19
0
 def test_keyword_arguments(self):
     result = given("a")(lambda x, y, z: x + y + z, y="b", z="c").end
     self.assertEqual(result, "abc")
示例#20
0
 def test_keyword_arguments(self):
     result = given("a")(lambda x, y, z: x + y + z, y="b", z="c").end
     self.assertEqual(result, "abc")
示例#21
0
 def test_single_generator(self):
     result = given([1, 2, 3])(i*2 for i in ANS)(list).end
     self.assertEqual(result, [2, 4, 6])
示例#22
0
 def test_explicit_keyword_arguments(self):
     result = given("z")(lambda x, y, z: x + y + z, x="x", y="y", z=ANS).end
     self.assertEqual(result, "xyz")
示例#23
0
 def test_unexistent_method(self):
     message = "'str' object has no attribute 'thing'"
     with self.assertRaisesRegex(AttributeError, message):
         given("a").thing()
示例#24
0
 def test_many_explicit_keyword_arguments(self):
     result = given("z")(lambda x, y, z: x + y + z, x=ANS, y=ANS, z=ANS).end
     self.assertEqual(result, "zzz")
示例#25
0
 def test_unpack_false(self):
     vector = (given([1, 2])
         (unpack, lambda x, y: [x, y])
         (lambda x: x*2)
     .end)
     self.assertEqual(vector, [1, 2, 1, 2])
示例#26
0
 def test_positional_and_keyword_arguments(self):
     result = given(9)(lambda x, y: x + y, ANS, y=ANS).end
     self.assertEqual(result, 18)
示例#27
0
 def test_unexistent_method(self):
     message = "'str' object has no attribute 'thing'"
     with self.assertRaisesRegex(AttributeError, message):
         given("a").thing()
示例#28
0
 def test_single_generator(self):
     result = given([1, 2, 3])(i * 2 for i in ANS)(list).end
     self.assertEqual(result, [2, 4, 6])
示例#29
0
 def test_first_argument(self):
     description = R"Expected 'callable' or 'generator'. Got 'int'"
     with self.assertRaisesRegex(TypeError, description):
         given(9)(8).end
示例#30
0
 def test_two_generators(self):
     result = given([1, 2,
                     3])(i * 2 for i in ANS)(i * 3 for i in ANS)(list).end
     self.assertEqual(result, [6, 12, 18])
示例#31
0
 def test_single_function(self):
     result = given(15)(lambda x: x + 15).end
     self.assertEqual(result, 30)
示例#32
0
 def test_many_for_statements(self):
     description = R"Multiple for statement are not allowed."
     with self.assertRaisesRegex(SyntaxError, description):
         given([1, 2, 3])(i * j for i in range(3) for j in ANS).end
示例#33
0
 def test_positional_arguments(self):
     result = given("a.c")(str.replace, ".", "b").end
     self.assertEqual(result, "abc")
示例#34
0
 def test_product_method(self):
     expected = [(i, j) for i in "abc" for j in range(4)]
     result = (given("abc")(product, ANS,
                            range(4))((i, j) for i, j in ANS)(list).end)
     self.assertEqual(result, expected)
示例#35
0
 def test_many_explicit_positinonal_argument(self):
     result = given(9)(lambda x, y, z: x*y*z, ANS, ANS, ANS).end
     self.assertEqual(result, 729)
示例#36
0
 def test_ANS_in_second_for_iter_statement(self):
     description = R"Can not iterate over 'tuple_iterator', "\
                   "'ANS' constant only."
     with self.assertRaisesRegex(ValueError, description):
         given("abc")(i for i in (1, 2)).end
示例#37
0
 def test_explicit_keyword_arguments(self):
     result = given("z")(lambda x, y, z: x + y + z, x="x", y="y", z=ANS).end
     self.assertEqual(result, "xyz")
示例#38
0
 def test_generator_followed_with_a_second_argument(self):
     description = "Can not accept arguments if you pass "\
                   "a generator at first \(3 given\)\."
     with self.assertRaisesRegex(TypeError, description):
         given("abc")((i for i in ANS), 1, 2, z=3).end
示例#39
0
 def test_positional_and_keyword_arguments(self):
     result = given(9)(lambda x, y: x + y, ANS, y=ANS).end
     self.assertEqual(result, 18)
示例#40
0
 def test_ANS_in_second_for_iter_statement(self):
     description = R"Can not iterate over 'tuple_iterator', "\
                   "'ANS' constant only."
     with self.assertRaisesRegex(ValueError, description):
         given("abc")(i for i in (1, 2)).end
示例#41
0
 def test_two_generators(self):
     result = given([1, 2, 3])(i*2 for i in ANS)(i*3 for i in ANS)(list).end
     self.assertEqual(result, [6, 12, 18])
示例#42
0
 def test_list_unpack(self):
     vector = (given([1, 2, 3])
         (unpack, lambda x, y, z: (x, y, z))
     .end)
     self.assertEqual(vector, (1, 2, 3))
示例#43
0
 def test_list_unpack(self):
     vector = (given([1, 2, 3])(unpack, lambda x, y, z: (x, y, z)).end)
     self.assertEqual(vector, (1, 2, 3))
示例#44
0
 def test_method_binding(self):
     result = (given("abcdefghi").upper().replace("E", " ")(
         c.lower() for c in ANS)(list)("".join)).end
     self.assertEqual(result, "abcd fghi")
示例#45
0
 def test_generator_followed_with_a_second_argument(self):
     description = "Can not accept arguments if you pass "\
                   "a generator at first \(3 given\)\."
     with self.assertRaisesRegex(TypeError, description):
         given("abc")((i for i in ANS), 1, 2, z=3).end
示例#46
0
 def test_single_argument_unpack(self):
     one = (given(1)
         (unpack, lambda x: x)
     .end)
     self.assertEqual(one, 1)
示例#47
0
 def test_dict_unpack(self):
     vector = (given({"x": 1, "y": 2, "z": 3})
         (unpack, lambda x, y, z: (x, y, z))
     .end)
     self.assertEqual(vector, (1, 2, 3))
示例#48
0
 def test_single_argument_unpack(self):
     one = (given(1)(unpack, lambda x: x).end)
     self.assertEqual(one, 1)