Exemplo n.º 1
0
def test_create_file(tmpdir):
    """
    @type tmpdir: py._path.local.LocalPath
    """
    tmp_file = tmpdir.join('foo.txt')

    assert not tmp_file.exists()

    file_resource = pw.file(str(tmp_file), content='Boo')

    assert not tmp_file.exists()
    changes = file_resource.apply()

    assert not tmp_file.exists()
    changes[0].commit()

    assert tmp_file.exists()
    assert 'Boo' == tmp_file.read()

    changes = file_resource.rollback()

    assert tmp_file.exists()
    assert 'Boo' == tmp_file.read()

    changes[0].commit()

    assert not tmp_file.exists()
Exemplo n.º 2
0
def test_create_file(tmpdir):
    """
    @type tmpdir: py._path.local.LocalPath
    """
    tmp_file1 = tmpdir.join('foo1.txt')
    tmp_file2 = tmpdir.join('foo2.txt')
    tmp_file3 = tmpdir.join('foo3.txt')

    assert not tmp_file1.exists()
    assert not tmp_file2.exists()
    assert not tmp_file3.exists()

    ctx = Context()

    ctx.apply(
        pw.file(str(tmp_file1), 'foo1')
    )

    with resource_set(ctx, name='Fooo'):

        ctx.apply(
            pw.file(str(tmp_file2), 'foo2'),
            pw.file(str(tmp_file3), 'foo3')
        )

    changes = ctx.changeset()
    assert changes.needed()

    assert not tmp_file1.exists()
    assert not tmp_file2.exists()
    assert not tmp_file3.exists()

    changes.commit()

    assert tmp_file1.exists()
    assert tmp_file2.exists()
    assert tmp_file3.exists()

    assert 'foo1' == tmp_file1.read()
    assert 'foo2' == tmp_file2.read()
    assert 'foo3' == tmp_file3.read()
Exemplo n.º 3
0
import pywizard.api as pw
import os

ctx = pw.context(locals())


tmp_file1 = os.getcwd() + '/foo1.txt'
tmp_file2 = os.getcwd() + '/foo2.txt'
tmp_file3 = os.getcwd() + '/foo3.txt'

ctx.apply(
    pw.file(str(tmp_file1), 'foo1')
)

with pw.resource_set(ctx, name='Fooo'):

    ctx.apply(
        pw.file(str(tmp_file2), 'foo2'),
        pw.file(str(tmp_file3), 'foo3')
    )