Use of pytest fixture tmp_path in all tests by SandrineP · Pull Request #35 · QuantStack/git2cpp · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions test/conftest.py
25 changes: 10 additions & 15 deletions test/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
import pytest


working_dir = 'test/data/xtl'

@pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"])
def test_add(xtl_clone, git2cpp_path, all_flag):
with open("./test/data/xtl/mook_file.txt", "x"):
pass
def test_add(xtl_clone, git2cpp_path, tmp_path, all_flag):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"

p = xtl_path / "mook_file.txt"
p.write_text('')

with open("./test/data/xtl/mook_file_2.txt", "x"):
pass
p2 = xtl_path / "mook_file_2.txt"
p2.write_text('')

cmd_add = [git2cpp_path, 'add']
if all_flag != "":
cmd_add.append(all_flag)
else:
cmd_add.append("mook_file.txt")
p_add = subprocess.run(cmd_add, cwd=working_dir, text=True)
p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True)
assert p_add.returncode == 0

cmd_status = [git2cpp_path, 'status', "--long"]
p_status = subprocess.run(cmd_status, cwd=working_dir, capture_output=True, text=True)
p_status = subprocess.run(cmd_status, cwd=xtl_path, capture_output=True, text=True)
assert p_status.returncode == 0

assert "Changes to be committed" in p_status.stdout
Expand All @@ -32,9 +33,3 @@ def test_add(xtl_clone, git2cpp_path, all_flag):
assert "Untracked files" not in p_status.stdout
else:
assert "Untracked files" in p_status.stdout

os.remove("./test/data/xtl/mook_file.txt")
os.remove("./test/data/xtl/mook_file_2.txt")

# undo the add, to leave the test directory at the end the same as it was at the start
subprocess.run(cmd_add, cwd=working_dir, capture_output=True, text=True)
23 changes: 15 additions & 8 deletions test/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@
import pytest


working_dir = 'test/data/xtl'
def test_branch_list(xtl_clone, git2cpp_path, tmp_path):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"

def test_branch_list(xtl_clone, git2cpp_path):
cmd = [git2cpp_path, 'branch']
p = subprocess.run(cmd, capture_output=True, cwd=working_dir, text=True)
p = subprocess.run(cmd, capture_output=True, cwd=xtl_path, text=True)
assert p.returncode == 0
assert(p.stdout == '* master\n')


def test_branch_create_delete(xtl_clone, git2cpp_path):
def test_branch_create_delete(xtl_clone, git2cpp_path, tmp_path):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"

create_cmd = [git2cpp_path, 'branch', 'foregone']
p_create = subprocess.run(create_cmd, capture_output=True, cwd=working_dir, text=True)
p_create = subprocess.run(create_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_create.returncode == 0

list_cmd = [git2cpp_path, 'branch']
p_list = subprocess.run(list_cmd, capture_output=True, cwd=working_dir, text=True)
p_list = subprocess.run(list_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_list.returncode == 0
assert(p_list.stdout == ' foregone\n* master\n')

del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
subprocess.run(del_cmd, capture_output=True, cwd=working_dir, text=True)
p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=working_dir, text=True)
p_del = subprocess.run(del_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_del.returncode == 0

p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_list2.returncode == 0
assert(p_list2.stdout == '* master\n')
32 changes: 16 additions & 16 deletions test/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@
import pytest


working_dir = 'test/data/xtl'
def test_checkout(xtl_clone, git2cpp_path, tmp_path):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"

def test_checkout(xtl_clone, git2cpp_path):
create_cmd = [git2cpp_path, 'branch', 'foregone']
p_create = subprocess.run(create_cmd, capture_output=True, cwd=working_dir, text=True)
p_create = subprocess.run(create_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_create.returncode == 0

checkout_cmd = [git2cpp_path, 'checkout', 'foregone']
p_checkout = subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
p_checkout = subprocess.run(checkout_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_checkout.returncode == 0
assert(p_checkout.stdout == '');

branch_cmd = [git2cpp_path, 'branch']
p_branch = subprocess.run(branch_cmd, capture_output=True, cwd=working_dir, text=True)
p_branch = subprocess.run(branch_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_branch.returncode == 0
assert(p_branch.stdout == '* foregone\n master\n')

checkout_cmd[2] = 'master'
p_checkout2 = subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
p_checkout2 = subprocess.run(checkout_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_checkout2.returncode == 0

del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
p_del = subprocess.run(del_cmd, cwd=working_dir, text=True)
assert p_del.returncode == 0

def test_checkout_b(xtl_clone, git2cpp_path, tmp_path):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"

def test_checkout_b(xtl_clone, git2cpp_path):
checkout_cmd = [git2cpp_path, 'checkout', '-b', 'foregone']
p_checkout = subprocess.run(checkout_cmd, capture_output=True, cwd=working_dir, text=True)
p_checkout = subprocess.run(checkout_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_checkout.returncode == 0
assert(p_checkout.stdout == '');

branch_cmd = [git2cpp_path, 'branch']
p_branch = subprocess.run(branch_cmd, capture_output=True, cwd=working_dir, text=True)
p_branch = subprocess.run(branch_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_branch.returncode == 0
assert(p_branch.stdout == '* foregone\n master\n')

checkout_cmd.remove('-b')
checkout_cmd[2] = 'master'
p_checkout2 = subprocess.run(checkout_cmd, cwd=working_dir, text=True)
p_checkout2 = subprocess.run(checkout_cmd, cwd=xtl_path, text=True)
assert p_checkout2.returncode == 0

del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
p_del = subprocess.run(del_cmd, cwd=working_dir, text=True)
assert p_del.returncode == 0
p_branch2 = subprocess.run(branch_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_branch2.returncode == 0
assert(p_branch2.stdout == ' foregone\n* master\n')
13 changes: 4 additions & 9 deletions test/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
import pytest


def test_clone(git2cpp_path):
def test_clone(git2cpp_path, tmp_path, run_in_tmp_path):
url = 'https://github.com/xtensor-stack/xtl.git'
working_dir = 'test/data'

clone_cmd = [git2cpp_path, 'clone', url]
p_clone = subprocess.run(clone_cmd, capture_output=True, cwd = working_dir, text=True)
p_clone = subprocess.run(clone_cmd, capture_output=True, cwd = tmp_path, text=True)
assert p_clone.returncode == 0

assert os.path.exists(working_dir + '/xtl')
assert os.path.exists(working_dir + '/xtl/include')

cleanup_cmd = ['rm', '-rf', 'xtl']
p_cleanup = subprocess.run(cleanup_cmd, capture_output=True, cwd = working_dir, text=True)
assert p_cleanup.returncode == 0
assert os.path.exists(os.path.join(tmp_path, 'xtl'))
assert os.path.exists(os.path.join(tmp_path, 'xtl/include'))
20 changes: 11 additions & 9 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
import pytest


working_dir = 'test/data/xtl'

@pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"])
def test_commit(xtl_clone, git_config, git2cpp_path, monkeypatch, all_flag):
with open("./test/data/xtl/mook_file.txt", "x"):
pass
def test_commit(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, all_flag):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"

p = xtl_path / "mook_file.txt"
p.write_text('')

cmd_add = [git2cpp_path, 'add', "mook_file.txt"]
p_add = subprocess.run(cmd_add, cwd=working_dir, text=True)
p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True)
assert p_add.returncode == 0

cmd_status = [git2cpp_path, 'status', "--long"]
p_status = subprocess.run(cmd_status, capture_output=True, cwd=working_dir, text=True)
p_status = subprocess.run(cmd_status, capture_output=True, cwd=xtl_path, text=True)
assert p_status.returncode == 0

assert "Changes to be committed" in p_status.stdout
assert "new file" in p_status.stdout

cmd_commit = [git2cpp_path, 'commit', "-m", "test commit"]
p_commit = subprocess.run(cmd_commit, cwd=working_dir, text=True)
p_commit = subprocess.run(cmd_commit, cwd=xtl_path, text=True)
assert p_commit.returncode == 0

cmd_status_2 = [git2cpp_path, 'status', "--long"]
p_status_2 = subprocess.run(cmd_status_2, capture_output=True, cwd=working_dir, text=True)
p_status_2 = subprocess.run(cmd_status_2, capture_output=True, cwd=xtl_path, text=True)
assert p_status_2.returncode == 0
assert "mook_file" not in p_status_2.stdout
52 changes: 28 additions & 24 deletions test/test_status.py