Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
ci: Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetbrulee committed Jul 23, 2024
1 parent 53ac830 commit eb32afd
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 13 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Python package

on: [push]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "pypy3.9", "pypy3.10"]
exclude:
- os: macos-latest
python-version: "3.9"
- os: windows-latest
python-version: "3.9"

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests/ --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# demo, test folder
!demo/**
# testdata folder
!tests/testdata/**
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ pip install -r requirements.txt
python -m files_flattener.cli <directory> <output_file> [<ignore_file>]
```

#### Run the tests

```sh
pytest tests/
```

#### Build the package

Ensure `wheel` is installed:
Expand Down Expand Up @@ -108,10 +114,9 @@ Upload the distribution files to PyPI:

## TODO

- [ ] feat: Add support for spcifying the git repository to clone and flatten.
- [ ] refactor: Use click package to implement the CLI.
- [ ] Add dry-run mode to preview the output before writing to the file.

- [x] Use `.ignore` to exclude or include files for flattening.
- [ ] feat: Add dry-run mode to preview the output before writing to the file.

## License

Expand Down
4 changes: 0 additions & 4 deletions demo/target/.ignore

This file was deleted.

2 changes: 1 addition & 1 deletion files_flattener/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pathspec
from concurrent.futures import ThreadPoolExecutor

from .directory_handler import (
from .identifier_handler import (
DirectoryHandlerFactory,
LocalDirectoryHandler,
RemoteRepositoryHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
from .common import logger


class DirectoryHandler:
class IdentifierHandler:
def __init__(self, identifier):
self.identifier = identifier

def prepare(self):
raise NotImplementedError


class LocalDirectoryHandler(DirectoryHandler):
class LocalDirectoryHandler(IdentifierHandler):
def prepare(self):
self.local_directory = self.identifier


class RemoteRepositoryHandler(DirectoryHandler):
class RemoteRepositoryHandler(IdentifierHandler):
def prepare(self):
self.local_directory = tempfile.mkdtemp()
logger.warning(
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ colorlog
GitPython

# For development
pytest
twine
wheel
4 changes: 4 additions & 0 deletions tests/absimport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18 changes: 18 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import absimport # FIRST LINE
import pytest
from files_flattener.core import list_files
from files_flattener.identifier_handler import LocalDirectoryHandler


@pytest.mark.parametrize(
"identifier, ignore_file, ignored",
[
("tests/testdata/target", None, "folder1/file2.txt"),
("tests/testdata/target", "tests/testdata/.ignore", "folder1/file2.txt"),
],
)
def test_list_files(identifier, ignore_file, ignored):
files, handler = list_files(identifier, ignore_file)
assert isinstance(files, list)
assert isinstance(handler, LocalDirectoryHandler)
assert ignored not in files if ignore_file else ignored in files
1 change: 1 addition & 0 deletions tests/testdata/.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
folder1/file2.txt
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit eb32afd

Please sign in to comment.