Skip to content

Commit df8205b

Browse files
cleanup test; fix typos
1 parent add451d commit df8205b

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

tests/core/test_selector_native.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def test_expand_git_selection(
639639
def test_expand_git_selection_integration(tmp_path: Path, mocker: MockerFixture):
640640
repo_path = tmp_path / "test_repo"
641641
repo_path.mkdir()
642-
subprocess.run(["git", "init"], cwd=repo_path, check=True, capture_output=True)
642+
subprocess.run(["git", "init", "-b", "main"], cwd=repo_path, check=True, capture_output=True)
643643

644644
models: UniqueKeyDict[str, Model] = UniqueKeyDict("models")
645645
model_a_path = repo_path / "model_a.sql"
@@ -662,32 +662,23 @@ def test_expand_git_selection_integration(tmp_path: Path, mocker: MockerFixture)
662662
capture_output=True,
663663
)
664664

665-
result = subprocess.run(
666-
["git", "branch", "--show-current"],
667-
cwd=repo_path,
668-
check=True,
669-
capture_output=True,
670-
text=True,
671-
)
672-
default_branch = result.stdout.strip()
673-
674665
# no changes should select nothing
675666
git_client = GitClient(repo_path)
676667
selector = NativeSelector(mocker.Mock(), models)
677668
selector._git_client = git_client
678-
assert selector.expand_model_selections([f"git:{default_branch}"]) == set()
669+
assert selector.expand_model_selections([f"git:main"]) == set()
679670

680671
# modify A but dont stage it, should be only selected
681672
model_a_path.write_text("SELECT 10 AS a")
682-
assert selector.expand_model_selections([f"git:{default_branch}"]) == {'"test_model_a"'}
673+
assert selector.expand_model_selections([f"git:main"]) == {'"test_model_a"'}
683674

684-
# stage model A, should still select it (this is the bug fix)
675+
# stage model A, should still select it
685676
subprocess.run(["git", "add", "model_a.sql"], cwd=repo_path, check=True, capture_output=True)
686-
assert selector.expand_model_selections([f"git:{default_branch}"]) == {'"test_model_a"'}
677+
assert selector.expand_model_selections([f"git:main"]) == {'"test_model_a"'}
687678

688679
# now add unstaged change to B and both should be selected
689680
model_b_path.write_text("SELECT 20 AS b")
690-
assert selector.expand_model_selections([f"git:{default_branch}"]) == {
681+
assert selector.expand_model_selections([f"git:main"]) == {
691682
'"test_model_a"',
692683
'"test_model_b"',
693684
}
@@ -707,7 +698,7 @@ def test_expand_git_selection_integration(tmp_path: Path, mocker: MockerFixture)
707698
)
708699

709700
# now A is committed in the dev branch and B unstaged but should both be selected
710-
assert selector.expand_model_selections([f"git:{default_branch}"]) == {
701+
assert selector.expand_model_selections([f"git:main"]) == {
711702
'"test_model_a"',
712703
'"test_model_b"',
713704
}

tests/utils/test_git_client.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def git_repo(tmp_path: Path) -> Path:
99
repo_path = tmp_path / "test_repo"
1010
repo_path.mkdir()
11-
subprocess.run(["git", "init"], cwd=repo_path, check=True, capture_output=True)
11+
subprocess.run(["git", "init", "-b", "main"], cwd=repo_path, check=True, capture_output=True)
1212
return repo_path
1313

1414

@@ -19,7 +19,7 @@ def test_git_uncommitted_changes(git_repo: Path):
1919
test_file.write_text("SELECT 1 AS a")
2020
subprocess.run(["git", "add", "model.sql"], cwd=git_repo, check=True, capture_output=True)
2121
subprocess.run(
22-
["git", "commit", "-m", "onitial commit"],
22+
["git", "commit", "-m", "Initial commit"],
2323
cwd=git_repo,
2424
check=True,
2525
capture_output=True,
@@ -48,7 +48,7 @@ def test_git_both_staged_and_unstaged_changes(git_repo: Path):
4848
file2.write_text("SELECT 2")
4949
subprocess.run(["git", "add", "."], cwd=git_repo, check=True, capture_output=True)
5050
subprocess.run(
51-
["git", "commit", "-m", "onitial commit"],
51+
["git", "commit", "-m", "Initial commit"],
5252
cwd=git_repo,
5353
check=True,
5454
capture_output=True,
@@ -58,7 +58,7 @@ def test_git_both_staged_and_unstaged_changes(git_repo: Path):
5858
file1.write_text("SELECT 10")
5959
subprocess.run(["git", "add", "model1.sql"], cwd=git_repo, check=True, capture_output=True)
6060

61-
# mdify file2 but don't stage it!
61+
# modify file2 but don't stage it!
6262
file2.write_text("SELECT 20")
6363

6464
# both should be detected
@@ -99,20 +99,11 @@ def test_git_committed_changes(git_repo: Path):
9999
test_file.write_text("SELECT 1")
100100
subprocess.run(["git", "add", "model.sql"], cwd=git_repo, check=True, capture_output=True)
101101
subprocess.run(
102-
["git", "commit", "-m", "onitial commit"],
103-
cwd=git_repo,
104-
check=True,
105-
capture_output=True,
106-
)
107-
108-
result = subprocess.run(
109-
["git", "branch", "--show-current"],
102+
["git", "commit", "-m", "Initial commit"],
110103
cwd=git_repo,
111104
check=True,
112105
capture_output=True,
113-
text=True,
114106
)
115-
default_branch = result.stdout.strip()
116107

117108
subprocess.run(
118109
["git", "checkout", "-b", "feature"],
@@ -130,7 +121,7 @@ def test_git_committed_changes(git_repo: Path):
130121
capture_output=True,
131122
)
132123

133-
committed = git_client.list_committed_changed_files(target_branch=default_branch)
124+
committed = git_client.list_committed_changed_files(target_branch="main")
134125
assert len(committed) == 1
135126
assert committed[0].name == "model.sql"
136127

0 commit comments

Comments
 (0)