Esempio n. 1
0
def test_exclude_directory(test_path):
    one = "node_modules/one.js"
    two = "packages/foo/node_modules/two.js"
    for f in one, two:
        ensure_matching_file(f)

    replacer.main(["old", "new", "--go", "--exclude", "node_modules/*"])
    assert_not_replaced(one)
    assert_not_replaced(two)
Esempio n. 2
0
def test_truncate_long_lines(test_path, long_line, capsys):
    test_txt = test_path.joinpath("test.txt")
    test_txt.write_text("This is an old short line\n")
    test_txt.write_text(long_line, append=True)

    replacer.main(["old", "new"])

    stdout, _ = capsys.readouterr()
    assert re.search("-- .* - I'm old - .*", stdout)
    assert re.search(r"\+\+ .* - I'm new - .*", stdout)
    print(stdout)
Esempio n. 3
0
def test_replace_in_files(capsys, test_path):

    replacer.main(["old", "new"])
    stdout, _ = capsys.readouterr()

    assert "top.txt" in stdout
    assert "other.txt" not in stdout

    # Dry-run: files should not have changed:
    assert_not_replaced("top.txt")

    # Now re-run with --go
    replacer.main(["old", "new", "--go"])
    assert_replaced("top.txt")
Esempio n. 4
0
def main(argv=sys.argv, config_path='tkgen.cfg'):
    opt_parser = OptionParser()
    opt_parser.add_option('-a', '--all', action='store_true', default=False,
                          dest='all',
                          help="process all source files regardless of whether it is updated")
    opts, args = opt_parser.parse_args()

    return replacer.main(opts=opts, config_path=config_path)
Esempio n. 5
0
def test_exclude_extension(test_path):
    replacer.main(["old", "new", "--go", "--exclude", "*.txt"])
    assert_not_replaced("top.txt")
    assert_replaced("b_dir/file.noext")
Esempio n. 6
0
def test_hidden(test_path):
    replacer.main(["old", "new", "--go"])
    assert_not_replaced(".hidden/hidden.txt")

    replacer.main(["old", "new", "--go", "--no-skip-hidden"])
    assert_replaced(".hidden/hidden.txt")
Esempio n. 7
0
def test_help(capsys):
    with pytest.raises(SystemExit) as e:
        replacer.main(["--help"])
    stdout, _ = capsys.readouterr()
    assert "usage" in stdout
    assert (e.value.code) == 0
Esempio n. 8
0
def test_non_utf_8(test_path, monkeypatch):
    # Just check it does not crash
    latin_1_encoded = "café".encode("latin-1")
    test_path.joinpath("non-utf8.txt").write_bytes(latin_1_encoded)
    replacer.main(["old", "new"])
Esempio n. 9
0
def test_backup(test_path):
    replacer.main(["old", "new", "--go", "--backup"])
    top_backup = test_path.files("*.back")[0]
    assert "old" in top_backup.text()
Esempio n. 10
0
def test_skip_binaries(test_path):
    ensure_matching_file("foo.exe", binary=True)
    replacer.main(["old", "new"])
    assert_not_replaced("foo.exe")
Esempio n. 11
0
 def test_main(self):
     replacer.Replacer.self_object = replacer.Replacer()
     replacer.main()
Esempio n. 12
0
 def test_main(self):
     replacer.Replacer.self_object = replacer.Replacer()
     replacer.main()