Example #1
0
def test_build_errors(popen_mock, progress_bar_mock, prevent_deadlock_mock,
                      open_mock, init_mock):
    popen_mock.return_value.poll.return_value = 1  # set to 1 for error
    output_str = "normal output..."
    error_str = "error message..."
    build_output = MagicMock()
    build_output.decode.return_value = output_str
    error_output = MagicMock()
    error_output.decode.return_value = error_str
    popen_mock.return_value.communicate.return_value = (build_output,
                                                        error_output)

    build = BuildCommand({'build': True,
                          '--watch': False,
                          '--verbose': False})
    build.config = MagicMock()

    with catch_stdout() as caught_output:
        with pytest.raises(SystemExit):
            build.action()
        output = caught_output.getvalue()

    # assert that we got the normal output and then the error output
    output_location = output.find(output_str)
    error_location = output.find(error_str)
    assert all(var >= 0 for var in (output_location, error_location))
    assert output_location < error_location
Example #2
0
def test_build_get_template_parameters(progress_bar_mock,
                                       popen_mock, prevent_deadlock_mock,
                                       open_mock, init_mock,
                                       template_parameters,
                                       get_template_parameters_mock):
    progress_bar_mock.duration_progress.side_effect = \
        lambda x, y, z: print('Building')

    build = BuildCommand({'build': True,
                          '--watch': False,
                          '--verbose': False})
    build.config = MagicMock()

    get_template_parameters_mock.return_value = template_parameters

    with catch_stdout() as caught_output:
        build.action()
        output = caught_output.getvalue()

    # assert that we started build, then did build process, then built
    starting = output.find('Starting build')
    building = output.find('Building')
    built = output.find('Built')
    assert all(var >= 0 for var in (starting, building, built))
    assert starting < building < built
Example #3
0
def test_watch_build(observer, sleep_mock, open_mock, init_mock):
    sleep_mock.side_effect = KeyboardInterrupt

    build = BuildCommand({'build': True, '--watch': True})
    build.config = MagicMock()

    with patch('mlt.commands.build.EventHandler') as event_handler_patch:
        build.action()
Example #4
0
def test_build_verbose(popen_mock, open_mock, init_mock):
    build = BuildCommand({'build': True, '--watch': False, '--verbose': True})
    build.config = MagicMock()

    with catch_stdout() as caught_output:
        build.action()
        output = caught_output.getvalue()

    # assert that we started build, then did build process, then built
    starting = output.find('Starting build')
    built = output.find('Built')
    assert all(var >= 0 for var in (starting, built))
    assert starting < built
Example #5
0
def test_simple_build(progress_bar_mock, popen_mock, open_mock, init_mock):
    progress_bar_mock.duration_progress.side_effect = \
        lambda x, y, z: print('Building')

    build = BuildCommand({'build': True, '--watch': False})
    build.config = MagicMock()

    with catch_stdout() as caught_output:
        build.action()
        output = caught_output.getvalue()

    # assert that we started build, then did build process, then built
    starting = output.find('Starting build')
    building = output.find('Building')
    built = output.find('Built')
    assert all(var >= 0 for var in (starting, building, built))
    assert starting < building < built
Example #6
0
def verify_build(args):
    """runs a full build if no build json file"""
    if not os.path.isfile('.build.json'):
        BuildCommand(args).action()