Пример #1
0
        class evaluated_tests(Fixtures):
            def _test(self, actual, expected, *, a_value, b_value=0):
                self.assertEqual(actual + b_value, expected)

            with options(a_value=13):
                @evaluated
                def a(self, *, a_value):
                    return a_value + 1, 14

                b = 1, 1

            @evaluated
            def raises_during_evaluation(self, *, a_value):
                self.fail("example failure")

            @evaluated
            def raises_during_test(self, *, a_value):
                return a_value + 1, 14

            @evaluated
            def inserts_option(self, *, a_value):
                return 1, 3, options(b_value=2)

            @evaluated
            def inserts_duplicate_option(self, *, a_value):
                return 1, 3, options(a_value=1)

            inline_evaluation = evaluated(lambda *a, **k: (1, 3)), options(b_value=2)
Пример #2
0
        class option_tests(Fixtures):
            def _test(self, a, b, *, expected):
                self.assertEqual(expected, a + b)

            kwoarg_as_options = 1, 2, options(expected=3)
            pokarg_as_options = 1, options(b=2, expected=3)

            missing_kwoarg = 1, 2
            duplicate_argument = 2, options(a=1, expected=3)
Пример #3
0
 class sum_tests(Fixtures):
     def _test(self, total, *terms, optional=0):
         self.assertEqual(total, sum(terms) + optional)
     a = 3, 2, 1
     b = 6, 3, 2, 1
     c = 15, 5, 3
     d = 4, 2, 2
     optional_success = 6, 3, 2, options(optional=1)
     optional_failure = 1, 3, 2, options(optional=1)
     optional_badargs = 3, 2, 1, options(doesntexist=1)
Пример #4
0
        class option_cm_test(Fixtures):
            def _test(self, a, b, *, c="", expected):
                self.assertEqual(expected, a + b + c)

            with options(expected="abc"):
                one_context_fail = "a", "b"
                one_context_good = "a", "bc"

                with options(c="c"):
                    two_contexts_good = "a", "b"
                    two_contexts_fail = "a", "bc"
                    two_contexts_and_override = "a", "bc", options(expected="abcc")

                with options(expected="def"):
                    context_override_good = "de", "f"
                    context_override_fail = "ab", "c"

                after_inner_context_exit = "ab", "c"
            after_all_context_exit = "a", "b"
Пример #5
0
        class option_tests(Fixtures):
            def _test(self, expected_result, *terms, operation=sum, modulo=None):
                result = operation(terms)
                if modulo is not None:
                    result = result % modulo
                self.assertEqual(expected_result, result)

            not_using_options = 5, 2, 3
            has_options = 6, 2, 3, options(operation=mul)
            has_multiple_options_one_call = 1, 2, 3, options(operation=mul, modulo=5)
            has_multiple_options_multiple_calls = 1, 2, 3, options(operation=mul), options(modulo=5)
            has_interleaved_option_calls = 1, options(operation=mul), 2, options(modulo=5), 3

            fails_assertion = 0, 2, 3, options(operation=mul, modulo=5)
Пример #6
0
 def inserts_duplicate_option(self, *, a_value):
     return 1, 3, options(a_value=1)
Пример #7
0
 def inserts_option(self, *, a_value):
     return 1, 3, options(b_value=2)
Пример #8
0
        class superclass(Fixtures):
            def _test(self, s, expected, *, suffix="default"):
                self.assertEqual(s + suffix, expected)

            a = "a", "ax"
            b = "b", "bdefault", options(suffix=skip_option)