Exemple #1
0
def test_touch_updates_mtime_leaves_content_intact(tmpdir):
    reference = str(tmpdir / 'reference')
    with open(reference, 'w') as r:
        r.write('Hello world')
    c = Component()
    os.utime(reference, (0, 0))
    c.touch(reference)
    assert os.stat(reference).st_mtime != 0
    with open(reference, 'r') as r:
        assert 'Hello world' == r.read()
Exemple #2
0
def test_touch_updates_mtime_leaves_content_intact(tmpdir):
    reference = str(tmpdir / "reference")
    with open(reference, "w") as r:
        r.write("Hello world")
    c = Component()
    os.utime(reference, (0, 0))
    c.touch(reference)
    assert os.stat(reference).st_mtime != 0
    with open(reference, "r") as r:
        assert "Hello world" == r.read()
Exemple #3
0
def test_chdir_contextmanager_is_stackable():
    outer = os.getcwd()
    inner1 = os.path.join(os.path.dirname(__file__), 'fixture')
    inner2 = os.path.join(os.path.dirname(__file__))
    c = Component()
    with c.chdir(inner1):
        assert inner1 == os.getcwd()
        with c.chdir(inner2):
            assert inner2 == os.getcwd()  # noqa
        assert inner1 == os.getcwd()
    assert outer == os.getcwd()
Exemple #4
0
def test_component_with_unknown_arguments_raises_valueerror():
    # Regression against bug #65
    with pytest.raises(ValueError) as e:
        Component("foo")
    assert str(e.value) == "Namevar is undefined for this component."
    with pytest.raises(ValueError) as e:
        Component(asdf="foo")
    assert str(e.value) == (
        "The following arguments are unacceptable for this component "
        "because they are either undefined or would override "
        "methods: asdf")
Exemple #5
0
def test_recursive_sub_component_iterator(root):
    for x in range(3):
        c = Component(name='x{}'.format(x))
        root.component += c
        for y in range(2):
            c2 = Component(name='x{}y{}'.format(x, y))
            c += c2

    recursive = list(x.name for x in root.component.recursive_sub_components)
    assert (['x0', 'x0y0', 'x0y1',
             'x1', 'x1y0', 'x1y1',
             'x2', 'x2y0', 'x2y1'] == recursive)
Exemple #6
0
def test_acic_does_not_raise_if_newer(root):
    c = Component()
    c.last_updated = Mock(return_value=22)
    root.component += c
    c2 = Component()
    c2.last_updated = Mock(return_value=21)
    c.assert_component_is_current(c2)
Exemple #7
0
def test_acic_accepts_multiple_components(root):
    c = Component()
    c.last_updated = Mock(return_value=20)
    root.component += c
    c2 = Component()
    c2.last_updated = Mock(return_value=21)
    with pytest.raises(batou.UpdateNeeded):
        c.assert_component_is_current([c2, c2])
Exemple #8
0
def test_acic_raises_if_older_reference(root):
    c = Component()
    c.last_updated = Mock(return_value=20)
    root.component += c
    c2 = Component()
    c2.last_updated = Mock(return_value=21)
    with pytest.raises(batou.UpdateNeeded):
        c.assert_component_is_current(c2)
Exemple #9
0
def test_cmd_execution_failed_gives_command_in_exception(mockroot):
    c = Component()
    c.prepare(mockroot)
    with pytest.raises(CmdExecutionError) as e:
        c.cmd('asdf')
    assert e.value.cmd == 'asdf'
    assert e.value.returncode == 127
Exemple #10
0
def test_cmd_should_not_stop_if_process_expects_input(mockroot):
    c = Component()
    c.prepare(mockroot)
    stdout, stderr = c.cmd('cat')
Exemple #11
0
def test_init_with_no_arguments_creates_plain_component():
    component = Component()
    # Lazy initialized attribute
    assert not hasattr(component, 'sub_components')
Exemple #12
0
def test_init_keyword_args_update_dict():
    component = Component(foobar=1)
    assert 1 == component.foobar
Exemple #13
0
def test_assert_no_changes_recursive_does_not_raise(root):
    root.component += Component()
    root.component.assert_no_changes()
Exemple #14
0
def test_assert_cmd_when_succesful(mockroot):
    c = Component()
    c.prepare(mockroot)
    c.assert_cmd('true')
Exemple #15
0
def test_require_one_convenience_raises_if_no_result():
    c = Component()
    c.require = Mock(return_value=[])
    with pytest.raises(SilentConfigurationError):
        c.require_one('asdf')
Exemple #16
0
def test_plain_component_runs_noop_configure_verify_update():
    component = Component()
    component.configure()
    component.verify()
    component.update()
Exemple #17
0
def test_cmd_returns_output(mockroot):
    c = Component()
    c.prepare(mockroot)
    assert ('1\n', '') == c.cmd('echo 1')
Exemple #18
0
def test_cmd_expands_jinja(mockroot):
    c = Component()
    c.foo = 'asdf'
    c.prepare(mockroot)
    assert ('asdf\n', '') == c.cmd('echo "{{component.foo}}"')
Exemple #19
0
def test_last_updated_not_implemented_on_base():
    c = Component()
    with pytest.raises(NotImplementedError):
        c.last_updated()
Exemple #20
0
def test_cmd_raises_if_error(mockroot):
    c = Component()
    c.prepare(mockroot)
    with pytest.raises(CmdExecutionError):
        c.cmd('non-existing-command')
Exemple #21
0
def test_require_one_convenience_api_returns_scalar():
    c = Component()
    c.require = Mock(return_value=[1])
    assert 1 == c.require_one('asdf')
Exemple #22
0
def test_cmd_returns_output_if_ignore_returncode(mockroot):
    c = Component()
    c.prepare(mockroot)
    out, err = c.cmd('echo important output && false', ignore_returncode=True)
    assert 'important output\n' == out
Exemple #23
0
def test_require_one_convenience_raises_if_more_results():
    c = Component()
    c.require = Mock(return_value=[1, 2])
    with pytest.raises(KeyError):
        c.require_one('asdf')
Exemple #24
0
def test_ansc_raises_if_subcomponent_changed(root):
    c2 = Component()
    root.component += c2
    c2.changed = True
    with pytest.raises(batou.UpdateNeeded):
        root.component.assert_no_subcomponent_changes()
Exemple #25
0
def test_assert_cmd_when_unsuccessful(mockroot):
    c = Component()
    c.prepare(mockroot)
    with pytest.raises(UpdateNeeded):
        c.assert_cmd('false')
Exemple #26
0
def test_afic_raises_if_file_isolder_than_reference(tmpdir, root):
    component = Component()
    root.component += component
    with pytest.raises(batou.UpdateNeeded):
        component.assert_file_is_current(__file__, [str(tmpdir)])
Exemple #27
0
def test_assert_no_changes_recursive_raises(root):
    c2 = Component()
    root.component += c2
    c2.changed = True
    with pytest.raises(batou.UpdateNeeded):
        root.component.assert_no_changes()
Exemple #28
0
def test_afic_doesnt_raise_if_file_exists_but_no_reference_is_given(root):
    component = Component()
    root.component += component
    component.assert_file_is_current(__file__)
Exemple #29
0
def test_touch_creates_new_file(tmpdir):
    reference = str(tmpdir / 'reference')
    assert not os.path.exists(reference)
    c = Component()
    c.touch(reference)
    assert os.path.exists(reference)
Exemple #30
0
def test_ansc_does_not_raise_if_no_subcomponent_changed(root):
    c2 = Component()
    root.component += c2
    c2.changed = False
    root.component.assert_no_subcomponent_changes()