Example #1
0
def test_check_file(tmpdir, example):

    check_file(name="test.txt",
               content=example.readlines(),
               tmpdir=str(tmpdir),
               normalize=[])
    assert tmpdir.join("test_simplefactory.py").check()
Example #2
0
def test_check_file(tmpdir, example):

    check_file(
        file=example,
        tmpdir=tmpdir,
    )
    assert tmpdir.join('test_simplefactory.py').check()
Example #3
0
def test_check_file(tmpdir, example):

    check_file(
        file=example,
        tmpdir=tmpdir,
    )
    assert tmpdir.join('test_simplefactory.py').check()
Example #4
0
def test_wipe(tmpdir):
    fp = tmpdir.join('simple.txt')
    fp.write('.. regendoc:wipe\n')
    check_file(
        file=fp,
        tmpdir=tmpdir)

    assert not tmpdir.listdir()
Example #5
0
def test_dotcwd(tmpdir):
    name = str(tmpdir.ensure('src/file'))
    check_file(
        name=name,
        content=['   . $ echo hi'],
        tmp_dir=str(tmpdir.ensure('tmp', dir=True)),
        normalize=[],
    )
Example #6
0
def test_wipe(tmpdir):
    fp = tmpdir.join("simple.txt")
    fp.write(".. regendoc:wipe\n")
    check_file(name="test",
               content=fp.readlines(),
               tmpdir=str(tmpdir),
               normalize=[])

    assert not tmpdir.listdir()
Example #7
0
def test_check_file(tmp_path: Path, example: Path) -> None:

    check_file(
        path=Path("test.txt"),
        content=example.read_text().splitlines(True),
        tmp_dir=tmp_path,
        normalize=[],
    )
    assert tmp_path.joinpath("test_simplefactory.py").is_file()
Example #8
0
def test_wipe(tmp_path: Path) -> None:
    fp = tmp_path / "example.txt"
    fp.write_text(".. regendoc:wipe\n")
    check_file(path=fp,
               content=fp.read_text().splitlines(),
               tmp_dir=tmp_path,
               normalize=[])

    assert not list(tmp_path.iterdir())
Example #9
0
def test_dotcwd(tmp_path: Path) -> None:
    name = tmp_path / "src/file"
    name.parent.mkdir()
    name.touch()
    tmp = tmp_path / "tmp"
    tmp.mkdir()
    check_file(
        path=name,
        content=["   . $ echo hi"],
        tmp_dir=tmp,
        normalize=[],
    )
Example #10
0
def test_docfile_chdir(tmpdir, monkeypatch):

    tmpdir.ensure("nested/file").write("some text\n")
    monkeypatch.chdir(tmpdir)
    filename = str(tmpdir.join("test.txt"))
    content = ["some shell test\n", "  nested $ cat file\n", "  some other text\n"]

    action, = parse_actions(content, file=filename)
    excpected_action = {
        "action": "shell",
        "content": "some other text\n",
        "cwd": "nested",
        "file": filename,
        "indent": 2,
        "line": 1,
        "target": "cat file",
    }
    assert action == excpected_action

    needed_updates = check_file(
        name="example.txt",
        content=content,
        tmp_dir=str(tmpdir.join("tmp")),
        normalize=[],
    )

    assert needed_updates
    # is it copied?
    assert tmpdir.join("tmp/nested/file").check()
Example #11
0
def test_docfile_chdir(tmp_path: Path,
                       monkeypatch: pytest.MonkeyPatch) -> None:
    path = tmp_path / "nested/file"
    path.parent.mkdir()

    path.write_text("some text\n")
    monkeypatch.chdir(path.parent)
    filename = tmp_path / "test.txt"
    content = [
        "some shell test\n", "  nested $ cat file\n", "  some other text\n"
    ]

    (action, ) = parse_actions(content, file=filename)
    excpected_action = Action(
        command=process,
        content="some other text\n",
        cwd=Path("nested"),
        file=filename,
        indent=2,
        line=1,
        target="cat file",
    )
    assert action == excpected_action

    needed_updates = check_file(
        path=tmp_path / "example.txt",
        content=content,
        tmp_dir=tmp_path / "tmp",
        normalize=[],
    )

    assert needed_updates
    # is it copied?
    assert tmp_path.joinpath("tmp/nested/file").is_file()
Example #12
0
def test_stripped_whitespace_no_update(tmpdir):
    raw = indented.splitlines(True)
    action, = check_file(name="example",
                         content=raw,
                         tmpdir=str(tmpdir),
                         normalize=[])
    assert action["content"] == action["new_content"]
    corrected = correct_content(raw, [action])
    assert raw == corrected
Example #13
0
def test_stripped_whitespace_no_update(tmp_path: Path) -> None:
    raw = indented.splitlines(True)
    (action, ) = check_file(path=Path("example"),
                            content=raw,
                            tmp_dir=tmp_path,
                            normalize=[])
    assert action.content == action.new_content
    corrected = correct_content(raw, [action])
    assert raw == corrected
Example #14
0
def test_simple_new_content(tmpdir):
    example = py.io.BytesIO(simple)
    needed_update, = check_file(
        file=example,
        tmpdir=tmpdir,
    )

    expected_update = {
        'action': 'shell',
        'cwd': None,
        'file': example,
        'target': 'echo hi',
        'content': 'oh no\n',
        'new_content': 'hi\n',
        'indent': 4,
        'line': 2,
    }
    print needed_update
    assert needed_update == expected_update
Example #15
0
def test_simple_new_content(tmpdir):
    example = py.io.BytesIO(simple)
    needed_update, = check_file(
        file=example,
        tmpdir=tmpdir,
    )

    expected_update = {
        'action': 'shell',
        'cwd': None,
        'file': example,
        'target': 'echo hi',
        'content': 'oh no\n',
        'new_content': 'hi\n',
        'indent': 4,
        'line': 2,
    }
    print needed_update
    assert needed_update == expected_update
Example #16
0
def test_simple_new_content(tmpdir):

    needed_update, = check_file(
        name="example",
        content=simple.splitlines(True),
        tmp_dir=str(tmpdir),
        normalize=[],
    )

    expected_update = {
        "action": "shell",
        "cwd": None,
        "file": "example",
        "target": "echo hi",
        "content": "oh no\n",
        "new_content": "hi\n",
        "indent": 4,
        "line": 2,
    }
    print(needed_update)
    assert needed_update == expected_update
Example #17
0
def test_simple_new_content(tmp_path: Path) -> None:

    (needed_update, ) = check_file(
        path=Path("example"),
        content=simple.splitlines(True),
        tmp_dir=tmp_path,
        normalize=[],
    )

    expected_update = Action(
        command=process,
        cwd=None,
        file=Path("example"),
        target="echo hi",
        content="oh no\n",
        new_content="hi\n",
        indent=4,
        line=2,
    )
    print(needed_update)
    assert needed_update == expected_update
Example #18
0
def test_docfile_chdir(tmpdir):

    tmpdir.ensure('nested/file').write('some text\n')
    example = tmpdir.join('example.txt')
    example.write('some shell test\n'
                  '  nested $ cat file\n'
                  '  some other text\n')

    action, = list(actions_of(example))
    excpected_action = {
        'action': 'shell',
        'file': example,
        'content': 'some other text\n',
        'cwd': 'nested',
        'indent': 2,
        'line': 1,
        'target': 'cat file',
    }
    assert action == excpected_action

    needed_updates = check_file(example, tmpdir)
    pprint.pprint(needed_updates)
    assert needed_updates
Example #19
0
def test_docfile_chdir(tmpdir):

    tmpdir.ensure('nested/file').write('some text\n')
    example = tmpdir.join('example.txt')
    example.write('some shell test\n'
                  '  nested $ cat file\n'
                  '  some other text\n')

    action, = list(actions_of(example))
    excpected_action = {
        'action': 'shell',
        'file': example,
        'content': 'some other text\n',
        'cwd': 'nested',
        'indent': 2,
        'line': 1,
        'target': 'cat file',
    }
    assert action == excpected_action

    needed_updates = check_file(example, tmpdir)
    py.std.pprint.pprint(needed_updates)
    assert needed_updates