Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit d8e794f

Browse files
OCoppingcoretl
authored andcommitted
Created list_branches method in __main__.py as branch checking is used multiple times; Removed check_branches from tests file as no longer needed as a result of adding list_branches.
1 parent 1e30877 commit d8e794f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/dls_python3_skeleton/__main__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
from subprocess import STDOUT, CalledProcessError, check_output
77
from tempfile import TemporaryDirectory
8+
from typing import List
89

910
from . import __version__
1011

@@ -37,6 +38,10 @@ def git(*args, cwd=None) -> str:
3738
raise
3839

3940

41+
def list_branches(path: Path) -> List[str]:
42+
return git("branch", "--format=%(refname:short)", cwd=path).split("\n")
43+
44+
4045
class GitTemporaryDirectory(TemporaryDirectory):
4146
def __enter__(self):
4247
return self
@@ -66,7 +71,7 @@ def replace_text(text: str) -> str:
6671
text = text.replace("[email protected]", email)
6772
return text
6873

69-
branches = [x[2:] for x in str(git("branch", "--list", cwd=path)).split("\n")]
74+
branches = list_branches(path)
7075

7176
if MERGE_BRANCH in branches:
7277
raise Exception(
@@ -189,7 +194,7 @@ def clean_repo(args):
189194

190195
assert path.is_dir(), f"Expected {path} to be an existing directory"
191196

192-
branches = [x[2:] for x in str(git("branch", "--list")).split("\n")]
197+
branches = list_branches(path)
193198
assert (
194199
f"{MERGE_BRANCH}" in branches
195200
), f"Expected {MERGE_BRANCH} to be in existing repo"

tests/test_dls_python3_skeleton.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sys
33
from configparser import ConfigParser
44
from pathlib import Path
5-
from typing import List
65

76
import pytest
87

@@ -18,10 +17,6 @@ def check_output(*args, cwd=None) -> str:
1817
raise ValueError(e.output)
1918

2019

21-
def check_branches(module: str) -> List[str]:
22-
return __main__.git("branch", "--format=%(refname:short)", cwd=module).split("\n")
23-
24-
2520
def test_cli_version():
2621
output = check_output(sys.executable, "-m", "dls_python3_skeleton", "--version")
2722
assert output.strip() == __version__
@@ -117,7 +112,7 @@ def test_existing_module(tmp_path: Path):
117112
in str(excinfo.value)
118113
)
119114

120-
branches = check_branches(str(module))
115+
branches = __main__.list_branches(module)
121116
assert MERGE_BRANCH in branches
122117
output = check_output(
123118
sys.executable,
@@ -128,5 +123,5 @@ def test_existing_module(tmp_path: Path):
128123
cwd=str(module),
129124
)
130125
assert output.strip("\n") == f"{MERGE_BRANCH} deleted from existing repo"
131-
branches = check_branches(str(module))
126+
branches = __main__.list_branches(module)
132127
assert MERGE_BRANCH not in branches

0 commit comments

Comments
 (0)