Skip to content

Commit cdfcb31

Browse files
Ci integration (#2)
* ci added * ci added * ci added * ci added * ci added * ci added
1 parent 8641431 commit cdfcb31

File tree

6 files changed

+94
-3
lines changed

6 files changed

+94
-3
lines changed

.github/workflows/python-ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Install dependencies (production)
25+
run: |
26+
pip install -r requirements.txt
27+
28+
- name: Install dev dependencies (for testing)
29+
run: |
30+
pip install -r dev-requirements.txt
31+
32+
- name: Run tests
33+
run: |
34+
pytest test_initializer.py

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ jobs:
5454
uses: pypa/gh-action-pypi-publish@release/v1
5555
with:
5656
packages-dir: dist/
57-
password: ${{ secrets.PYPI_API_TOKEN }}
57+
password: ${{ secrets.PYPI_API_TOKEN }}

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest==7.2.0
2+
PyYAML~=6.0

not_gitmodules/parts/delete_git.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
def delete_using_subprocess(path):
6-
subprocess.run(["rm", path, "-r", "-f" ], check=True)
6+
subprocess.run(["rm", path, "-r", "-f"], check=True)
77

88

99
def drop_read_only(path):
@@ -15,11 +15,20 @@ def drop_read_only(path):
1515

1616
def delete_git_folder(directory):
1717
"""Deletes .git folder from a directory"""
18-
git_folder_path = os.path.join(directory, '.git')
18+
git_folder_path = os.path.join(directory, ".git")
1919

2020
if os.path.exists(git_folder_path):
2121
try:
2222
shutil.rmtree(git_folder_path)
2323
except PermissionError:
2424
drop_read_only(git_folder_path)
2525
shutil.rmtree(git_folder_path)
26+
27+
28+
def force_del_file(path):
29+
return delete_using_subprocess(path)
30+
31+
32+
def force_del_folder(path):
33+
while os.path.exists(path):
34+
subprocess.run(["rm", "-r", path, "-f"], check=True)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
setuptools~=65.5.0
2+
PyYAML~=6.0

test_initializer.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import unittest
2+
from unittest.mock import patch, mock_open
3+
from not_gitmodules import initializer
4+
from not_gitmodules.cli import cli
5+
6+
7+
class TestInitializerFunction(unittest.TestCase):
8+
@patch(
9+
"builtins.open",
10+
new_callable=mock_open,
11+
read_data="repos:\n file_reader: https://github.com/Free-Apps-for-All/file_manager_git_module",
12+
)
13+
@patch("not_gitmodules.core.read_yaml")
14+
def test_initializer_with_valid_yaml(self, mock_read_yaml, mock_file):
15+
mock_read_yaml.return_value = {
16+
"repos": {
17+
"file_reader": "https://github.com/Free-Apps-for-All/file_manager_git_module"
18+
}
19+
}
20+
21+
initializer("notgitmodules.yaml")
22+
23+
mock_read_yaml.assert_called_once_with("notgitmodules.yaml")
24+
25+
@patch("builtins.open", new_callable=mock_open, read_data="repos:\n invalid_repo")
26+
def test_initializer_with_invalid_yaml(self, mock_file):
27+
with self.assertRaises(FileNotFoundError):
28+
initializer("notgitmodules.yaml")
29+
30+
@patch(
31+
"builtins.open",
32+
new_callable=mock_open,
33+
read_data="repos:\n file_reader: https://github.com/Free-Apps-for-All/file_manager_git_module",
34+
)
35+
@patch("not_gitmodules.core.read_yaml")
36+
def test_cli_with_default_input(self, mock_read_yaml, mock_file):
37+
with patch("builtins.input", return_value=""):
38+
cli()
39+
40+
mock_read_yaml.assert_called_once_with("notgitmodules.yaml")
41+
42+
43+
if __name__ == "__main__":
44+
unittest.main()

0 commit comments

Comments
 (0)