Skip to content

Commit

Permalink
refactor: run locally and pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artemrys committed Dec 25, 2021
1 parent b6426e1 commit ddae003
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Steps:
- `python3 -m venv .venv`
- `source .venv/bin/activate`
- `pip install lxml`
- `python requirement_file_checks/all.py --input <path-to-your-requiremenet-files>`
- `python run_all.py --input <path-to-your-requiremenet-files>`

# License

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions requirement_file_checks/base_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 2 additions & 17 deletions requirement_file_checks/all.py → run_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,17 @@
# 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
from requirement_file_checks.validate_xml import XMLChecker
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")
Expand Down
Empty file added tests/__init__.py
Empty file.
Empty file added tests/unit/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions tests/unit/test_all.py → tests/unit/test_base_checker.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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)

0 comments on commit ddae003

Please sign in to comment.