Skip to content

Commit 423b80e

Browse files
committed
further testing
1 parent cb45c04 commit 423b80e

16 files changed

+368
-124
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
ignore =
3+
# E501 line too long
4+
E501

.github/workflows/linter.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ jobs:
5959
FILTER_REGEX_EXCLUDE: .github/ISSUE_TEMPLATE/*
6060
# Lots of shellcheck errors - need fixing
6161
VALIDATE_BASH: false
62+
# Disable isort
63+
VALIDATE_PYTHON_ISORT: false

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
run: pip install -r requirements.txt
2424

2525
- name: Run Python Tests
26-
run: python -m unittest test
26+
run: python -m unittest discover tests

skaraMirror.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ Mirror the JDK 8 repository from a specific repository and branch:
4646
```bash
4747
./skaraMirror.py jdk8u [email protected]:custom_org custom_branch
4848
```
49+
50+
## Running tests
51+
52+
The tests for this codebase live in `/tests`. If you want to run them you can use the following command:
53+
54+
```bash
55+
python -m unittest discover tests
56+
```

skaraMirror.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ def perform_merge_into_release_from_master(workspace, github_repo, branch):
233233
)
234234
print(f"Tagging {tag} as {tag}_adopt")
235235
adoptTag = f"{tag}_adopt"
236-
repo.create_tag(adoptTag, ref=tag, message=f"Merged {tag} into release")
236+
repo.create_tag(
237+
adoptTag, ref="release", message=f"Merged {tag} into release"
238+
)
237239
newAdoptTags.append(adoptTag)
238240

239241
if repo.git.rev_parse(
@@ -274,6 +276,7 @@ def perform_merge_into_release_from_master(workspace, github_repo, branch):
274276

275277
if repo.git.tag("-l", prevReleaseAdoptTag):
276278
if not repo.git.tag("-l", currentReleaseAdoptTag):
279+
print("here")
277280
print(
278281
f"Tagging new current release tag {currentReleaseAdoptTag} "
279282
+ f"which is same commit as the previous {prevReleaseAdoptTag}"

test.py

Lines changed: 0 additions & 122 deletions
This file was deleted.

tests/__init__.py

Whitespace-only changes.

tests/supress_print.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import io
2+
import sys
3+
4+
5+
class SuppressPrint:
6+
def __enter__(self):
7+
self._original_stdout = sys.stdout
8+
sys.stdout = io.StringIO()
9+
return self
10+
11+
def __exit__(self, exc_type, exc_val, exc_tb):
12+
sys.stdout = self._original_stdout

tests/test_add_skara_upstream.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import unittest
2+
from unittest.mock import patch, MagicMock
3+
4+
from skaraMirror import add_skara_upstream
5+
from tests.supress_print import SuppressPrint
6+
7+
8+
class TestAddSkaraUpstream(unittest.TestCase):
9+
@patch("skaraMirror.Repo")
10+
def test_add_skara_remote_not_exist(self, mock_repo):
11+
# Setup: Configure the mock repo object
12+
mock_repo.return_value.remotes = MagicMock()
13+
mock_repo.return_value.remotes.__iter__.return_value = []
14+
15+
# Define your function parameters
16+
workspace = "/tmp/workspace"
17+
jdk_version = "jdk11u"
18+
skara_repo = "https://github.com/openjdk/skara"
19+
branch = "master"
20+
21+
# Execute the function
22+
with SuppressPrint():
23+
add_skara_upstream(workspace, jdk_version, skara_repo, branch)
24+
25+
# Assertions: Check if the remote was added
26+
mock_repo.return_value.create_remote.assert_called_once_with(
27+
"skara", skara_repo
28+
)
29+
30+
@patch("skaraMirror.Repo")
31+
def test_skara_remote_already_exists(self, mock_repo):
32+
# Setup: Simulate existing 'skara' remote
33+
mock_remote = MagicMock()
34+
mock_remote.name = "skara"
35+
mock_repo.return_value.remotes = MagicMock()
36+
mock_repo.return_value.remotes.__iter__.return_value = [mock_remote]
37+
38+
# Execute the function with the same parameters as before
39+
with SuppressPrint():
40+
add_skara_upstream(
41+
"/tmp/workspace", "jdk11u", "https://github.com/openjdk/skara", "master"
42+
)
43+
44+
# Assertions: Ensure create_remote was not called since 'skara' exists
45+
mock_repo.return_value.create_remote.assert_not_called()

tests/test_check_args.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
from unittest.mock import patch
3+
4+
from skaraMirror import check_args
5+
6+
7+
class TestCheckArgs(unittest.TestCase):
8+
@patch("sys.argv", ["script_name", "jdk8u", "https://example.com/repo", "dev"])
9+
def test_with_full_arguments(self):
10+
args = check_args()
11+
self.assertEqual(args.jdk_version, "jdk8u")
12+
self.assertEqual(args.repo_url, "https://example.com/repo")
13+
self.assertEqual(args.branch, "dev")
14+
15+
@patch("sys.argv", ["script_name", "jdk11u"])
16+
def test_with_minimum_arguments(self):
17+
args = check_args()
18+
self.assertEqual(args.jdk_version, "jdk11u")
19+
self.assertEqual(args.repo_url, "[email protected]:adoptium")
20+
self.assertEqual(args.branch, "master")

0 commit comments

Comments
 (0)