Пример #1
0
    def successful_assertion_with_reference_argument(self):
        with given:
            spec_contents = """from unittest import mock
from nimoy.specification import Specification


class JimbobSpec(Specification):
    def test(self):
        with setup:
            a = 3
            the_mock = mock.Mock()
        with when:
            the_mock.some_method(3, True)
        with then:
            1 * the_mock.some_method(a, True)
            """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == True
Пример #2
0
    def successful_chained_mock_assertion(self):
        spec_contents = """from unittest import mock
from nimoy.specification import Specification


class JimbobSpec(Specification):
    def test(self):
        with setup:
            the_mock = mock.Mock()
        with when:
            the_mock.some_method().then_do_something().or_another()
        with then:
            1 * the_mock.some_method()
            1 * the_mock.some_method.return_value.then_do_something()
            1 * the_mock.some_method.return_value.then_do_something.return_value.or_another()
        """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == True
Пример #3
0
    def string_diffs(self):
        with given:
            spec_contents = """from nimoy.specification import Specification
        
class JimbobSpec(Specification):
    
    def test(self):
        with given:
            a = 'The quick brown fox'
        with expect:
            a == 'The quick frown box'
            """

        with when:
            result = run_spec_contents(spec_contents)

        with then:
            result.wasSuccessful() == False
            failure_message = result.failures[0][1]
            "\'The quick frown box\'\n     but: was \'The quick brown fox\'" in failure_message
            "- The quick brown fox\n?           ^     ^" in failure_message
            "+ The quick frown box\n?           ^     ^" in failure_message
Пример #4
0
    def failed_chained_mock_assertion_with_arguments(self):
        with given:
            spec_contents = """from unittest import mock
from nimoy.specification import Specification


class JimbobSpec(Specification):
    def test(self):
        with setup:
            the_mock = mock.Mock()
        with when:
            the_mock.some_method(1).then_do_something("a").or_another(True)
        with then:
            1 * the_mock.some_method(1)
            1 * the_mock.some_method.return_value.then_do_something("b")
            1 * the_mock.some_method.return_value.then_do_something.return_value.or_another(True)
            """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == False
Пример #5
0
    def failed_assertion_with_left_shift(self):
        with given:
            spec_contents = """from unittest import mock
from nimoy.specification import Specification


class JimbobSpec(Specification):
    def test(self):
        with setup:
            the_mock = mock.Mock()
        with when:
            the_mock.some_method() << [5, 6, 7]
        with then:
            the_mock.some_method() == 7
            the_mock.some_method() == 6
            the_mock.some_method() == 5
            """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == False
Пример #6
0
    def successful_assertion_with_right_shift(self):
        with given:
            spec_contents = """from unittest import mock
from nimoy.specification import Specification


class JimbobSpec(Specification):
    def test(self):
        with setup:
            the_mock = mock.Mock()
        with when:
            the_mock.some_method() >> 5
        with then:
            the_mock.some_method() == 5
            the_mock.some_method() == 5
            the_mock.some_method() == 5
            """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == True
Пример #7
0
    def skipped_spec_is_not_reported(self):
        with given:
            spec_contents = """import unittest
from nimoy.specification import Specification

class JimbobSpec(Specification):
    def test(self):
        with expect:
            1 == 1
    
    @unittest.skip        
    def test2(self):
        with expect:
            1 == 2
"""

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == True
            result_output = result.stream.getvalue()
            result_output @ re.compile('Ran 1 test', re.MULTILINE)
Пример #8
0
    def matrix_form_multi_variables_with_a_single_value_and_fail(self):
        with given:
            spec_contents = """from nimoy.specification import Specification
        
class JimbobSpec(Specification):
    
    def test(self):
        with given:
            a = value_of_a
            b = value_of_b
            
        with expect:
            (a * b) == expected_value
        
        with where:
            value_of_a | value_of_b | expected_value
            2          | 1          | 10
            """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == False
Пример #9
0
    def single_variable_with_instance_function(self):
        with given:
            spec_contents = """from nimoy.specification import Specification
        
class JimbobSpec(Specification):
    
    def test(self):
        with given:
            a = value_of_a
            
        with expect:
            a == 0
        
        with where:
            value_of_a = self.set_of_numbers()
            
    def set_of_numbers(self):
        return [0, 0 ,0]
            """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == True
Пример #10
0
    def matrix_form_with_explicit_declaration(self):
        with given:
            spec_contents = """from nimoy.specification import Specification
        
class JimbobSpec(Specification):
    
    def test(self, value_of_a, value_of_b, expected_value):
        with given:
            a = value_of_a
            b = value_of_b
            
        with expect:
            (a * b) == expected_value
        
        with where:
            value_of_a | value_of_b | expected_value
            2          | 1          | 2
            
            """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == True
Пример #11
0
    def list_form_multi_variables_and_fail(self):
        with given:
            spec_contents = """from nimoy.specification import Specification
        
class JimbobSpec(Specification):
    
    def test(self):
        with given:
            a = value_of_a
            b = value_of_b
            
        with expect:
            (a * b) == expected_value
        
        with where:
            value_of_a = [1, 2]
            value_of_b = [1, 1]
            expected_value = [1, 5]
            """

        with when:
            result = run_spec_contents(spec_contents)
        with then:
            result.wasSuccessful() == False