Skip to content

Commit 003ba3b

Browse files
committed
Fix Python tests
1 parent 1784525 commit 003ba3b

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

flavors/lineageos/test_lineageos_updater.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,36 @@
33

44
from unittest.mock import patch
55
from typing import Any
6+
import subprocess
7+
import textwrap
68

79
import update_device_metadata
810
import update_device_dirs
911

1012

1113
def test_fetch_metadata(tmp_path: Any) -> None:
1214
lineage_build_targets = tmp_path / "lineage-build-targets"
13-
lineage_build_targets.write_text(
14-
'''# Ignore comments
15+
lineage_build_targets.write_text(textwrap.dedent('''
16+
# Ignore comments
1517
crosshatch userdebug lineage-18.1 W
16-
''')
18+
'''))
1719

1820
devices_json = tmp_path / "devices.json"
19-
devices_json.write_text(
20-
'''[
21-
{ "model": "crosshatch", "oem": "Google", "name": "Pixel 3 XL", "lineage_recovery": true}
21+
devices_json.write_text(textwrap.dedent('''
22+
[
23+
{ "model": "crosshatch", "oem": "Google", "name": "Pixel 3 XL", "lineage_recovery": true}
2224
]
23-
''')
25+
'''))
26+
27+
# nix-prefetch-git that is used underneath seems to require a real git repo
28+
subprocess.check_output(["git", "init", "--initial-branch=main"], cwd=tmp_path)
29+
subprocess.check_output(["git", "add", "-A"], cwd=tmp_path)
30+
subprocess.check_output(["git", "commit", "-am", "Initial commit"], cwd=tmp_path)
2431

2532
metadata = update_device_metadata.fetch_metadata(
26-
f"file://{lineage_build_targets}", f"file://{devices_json}"
33+
f"file://{tmp_path}",
34+
"lineage-build-targets",
35+
"devices.json"
2736
)
2837

2938
assert metadata == {
@@ -133,6 +142,8 @@ def test_fetch_vendor_dirs(ls_remote: Any, checkout_git: Any, tmpdir: Any) -> No
133142
"vendor": "google"
134143
},
135144
}
136-
dirs = update_device_dirs.fetch_vendor_dirs(metadata, baseurl, 'lineage-18.1')
145+
dirs = update_device_dirs.fetch_vendor_dirs(
146+
metadata, baseurl, 'lineage-18.1', 'lineage-18.1', {}
147+
)
137148

138149
assert 'vendor/google' in dirs

scripts/mk_repo_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
REPO_FLAGS = [
2323
"--quiet",
24-
"--repo-url=https://github.com/danielfullmer/tools_repo",
25-
"--repo-rev=9ecb9713ee5adba95120acbc0bfef1c77b02637f",
24+
"--repo-url=https://github.com/jaen/tools_repo",
25+
"--repo-rev=dca531f6d6e9fdcf00aa9d18f0153bd66a2e32ea",
2626
"--no-repo-verify",
2727
"--depth=1",
2828
]

scripts/robotnix_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def save(filename: str, data: Any) -> None:
3131

3232
def get_store_path(path):
3333
"""Get actual path to a Nix store path; supports handling local remotes"""
34-
prefix = os.getenv('NIX_REMOTE');
34+
prefix = os.getenv('NIX_REMOTE')
3535
if prefix and not prefix.startswith('/'):
3636
raise Exception('Must be run on a local Nix store.')
37-
return f"{prefix}/{path}"
37+
return os.path.join(*filter(None, [prefix, path]))
3838

3939
class GitCheckoutInfoDict(TypedDict):
4040
"""Container for output from nix-prefetch-git"""

scripts/test_mk_repo_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import mk_repo_file
1414

1515

16-
def git_create(directory: str, tag: Optional[str] = "release") -> None:
16+
def git_create(directory: str, tag: Optional[str] = "release", initial_branch: str = "main") -> None:
1717
"""Turn a directory into a git repo"""
1818
cwd = os.getcwd()
1919
os.chdir(directory)
20-
subprocess.check_call(["git", "init", "--initial-branch=master"])
20+
subprocess.check_call(["git", "init", f"--initial-branch={initial_branch}"])
2121
subprocess.check_call(["git", "config", "--local", "user.name", "testenv"])
2222
subprocess.check_call(["git", "config", "--local", "user.email", "testenv@example.com"])
2323
subprocess.check_call(["git", "add", "."])

0 commit comments

Comments
 (0)