Beispiel #1
0
def pageflow(fixture):
    fixture.start_example_app()
    fixture.driver_browser.open('/')
    fixture.driver_browser.type(XPath.input_labelled('Email address'),
                                '*****@*****.**')
    fixture.driver_browser.type(XPath.input_labelled('Comment'), '')
    with SystemOutStub() as output:
        fixture.driver_browser.click(XPath.button_labelled('Submit'))

        vassert(output.captured_output ==
                '[email protected] submitted a comment:\nNone\n')
        vassert(fixture.driver_browser.current_url.path == '/none')
        output.capture_console_screenshot(
            fixture.new_screenshot_path('pageflow1.txt'))

        fixture.driver_browser.open('/')
        fixture.driver_browser.type(XPath.input_labelled('Email address'),
                                    '*****@*****.**')
        fixture.driver_browser.type(XPath.input_labelled('Comment'),
                                    'some comment text')
        with SystemOutStub() as output:
            fixture.driver_browser.click(XPath.button_labelled('Submit'))

        vassert(output.captured_output ==
                '[email protected] submitted a comment:\nsome comment text\n')
        vassert(fixture.driver_browser.current_url.path == '/thanks')
        output.capture_console_screenshot(
            fixture.new_screenshot_path('pageflow2.txt'))
def handling_import_errors(fixture):
    """Should example code be broken enough to cause ImportErrors, such errors are 
       reported when an attempt is made to check it out."""

    fixture.example_module.change_contents(fixture.example_module_contents)
    fixture.containing_egg.activate()

    with SystemOutStub(), fixture.checkout_directory.as_cwd():
        command = fixture.GetExample(EmptyStub())
        with expected(fixture.expected_exception):
            command.do(fixture.command_line)
Beispiel #3
0
def test_handling_import_errors(import_error_scenarios):
    """Should example code be broken enough to cause ImportErrors, such errors are 
       reported when an attempt is made to check it out."""

    import_error_scenarios.example_module.change_contents(import_error_scenarios.example_module_contents)
    import_error_scenarios.containing_egg.activate()

    with SystemOutStub(), import_error_scenarios.checkout_directory.as_cwd():
        command = import_error_scenarios.GetExample()
        with expected(import_error_scenarios.expected_exception):
            command.do(import_error_scenarios.command_line)
Beispiel #4
0
    def test_stubbed_sysout(self):
        """A SystemOutStub can be used to capture console output. Such output can be captured as a "textual screenshot"."""
        def print_something():
            print('something')
            print('printed')

        with SystemOutStub() as output:
            print_something()

        assert output.captured_output == 'something\nprinted\n'

        screenshot_filename = tempfile.mktemp()
        output.capture_console_screenshot(screenshot_filename)

        with io.open(screenshot_filename, 'r') as screenshot:
            assert (screenshot.read() == output.captured_output)