diff --git a/README.md b/README.md index dbc865f..9035e28 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Steps: - `python3 -m venv .venv` - `source .venv/bin/activate` - `pip install lxml` -- `python requirement_file_checks/all.py --input ` +- `python run_all.py --input ` # License diff --git a/action.yml b/action.yml index 511e97e..76a10dc 100644 --- a/action.yml +++ b/action.yml @@ -27,5 +27,5 @@ runs: shell: bash - run: echo "TA REQUIREMENT LOGS UNIT TESTS STARTED:" shell: bash - - run: python ${{ github.action_path }}/requirement_file_checks/all.py ${{ inputs.input-files }} + - run: python ${{ github.action_path }}/run_all.py --input ${{ inputs.input-files }} shell: bash diff --git a/requirement_file_checks/base_checker.py b/requirement_file_checks/base_checker.py index 1486df2..4b48a2b 100644 --- a/requirement_file_checks/base_checker.py +++ b/requirement_file_checks/base_checker.py @@ -13,9 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import os from typing import List +def collect_filenames(path: str) -> List[str]: + filenames = [] + if os.path.exists(path): + if os.path.isfile(path): + filenames.append(path) + elif os.path.isdir(path): + for subdir, _, files in os.walk(path): + for file in files: + if file.endswith(".log"): + filename = os.path.join(subdir, file) + filenames.append(filename) + return filenames + + class BaseChecker: def __init__(self, print_prefix: str, filenames: List[str]): self.filenames = filenames diff --git a/requirement_file_checks/all.py b/run_all.py similarity index 77% rename from requirement_file_checks/all.py rename to run_all.py index ee9a4f9..9f04da1 100644 --- a/requirement_file_checks/all.py +++ b/run_all.py @@ -14,9 +14,8 @@ # limitations under the License. # import argparse -import os -from typing import List +from requirement_file_checks.base_checker import collect_filenames from requirement_file_checks.cim import CimChecker from requirement_file_checks.transport_attrib import TransportAttributesChecker from requirement_file_checks.unicode_char import UnicodeChecker @@ -24,22 +23,8 @@ from requirement_file_checks.xml_format_checker import XmlFormatChecker -def _collect_filenames(path: str) -> List[str]: - filenames = [] - if os.path.exists(path): - if os.path.isfile(path): - filenames.append(path) - elif os.path.isdir(path): - for subdir, _, files in os.walk(path): - for file in files: - if file.endswith(".log"): - filename = os.path.join(subdir, file) - filenames.append(filename) - return filenames - - def run(path: str): - filenames = _collect_filenames(path) + filenames = collect_filenames(path) print(f"Collected filenames: {filenames}") if not filenames: raise SystemExit("No files to check") diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/test_all.py b/tests/unit/test_base_checker.py similarity index 76% rename from tests/unit/test_all.py rename to tests/unit/test_base_checker.py index 6b8ebbb..2a2ee9d 100644 --- a/tests/unit/test_all.py +++ b/tests/unit/test_base_checker.py @@ -1,12 +1,12 @@ import os import tempfile -from requirement_file_checks import all +from requirement_file_checks import base_checker def test_collect_filenames_when_no_files(): with tempfile.TemporaryDirectory() as tempdir: - assert not all._collect_filenames(tempdir) + assert not base_checker.collect_filenames(tempdir) def test_collect_filenames_when_files(): @@ -21,4 +21,4 @@ def test_collect_filenames_when_files(): os.path.join(tempdir, "1.log"), os.path.join(tempdir, "folder", "2.log"), ] - assert expected_result == all._collect_filenames(tempdir) + assert expected_result == base_checker.collect_filenames(tempdir)