Lint tests, add tests to readme

This commit is contained in:
tntexplosivesltd 2023-11-24 21:03:15 +13:00
parent ec870e7771
commit 2639109aa3
5 changed files with 24 additions and 13 deletions

View File

@ -30,10 +30,10 @@ jobs:
- name: Install python libraries - name: Install python libraries
shell: bash shell: bash
run: | run: |
pip install black pylint -r tools/requirements.txt pip install black pylint pytest -r tools/requirements.txt
- name: Run pylint and black - name: Run pylint and black
shell: bash shell: bash
run: | run: |
pylint tools --ignore=build,tests pylint tools --ignore=build
black --check tools black --check tools

View File

@ -431,7 +431,8 @@ disable=raw-checker-failed,
use-symbolic-message-instead, use-symbolic-message-instead,
missing-class-docstring, missing-class-docstring,
missing-function-docstring, missing-function-docstring,
missing-module-docstring missing-module-docstring,
fixme
# Enable the message, report, category or checker with the given id(s). You can # Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option # either give multiple identifier separated by comma (,) or put this option

View File

@ -18,15 +18,26 @@ This verifies exports by comparing the exports of an original DLL and the recomp
## checkorder ## checkorder
This checks the order of C++ source and header files to make sure the functions are in order This checks the order of C++ source and header files to make sure the functions are in order
## isledecomp
This is a library that is used by rhe above scripts. it has a collection of useful classes and functions
### Testing
`isledecomp` has a small suite of tests. Install pylint and run it, passing in the directory:
```
pip install pytest
pytest tools/isledecomp/tests/
```
## Development ## Development
In order to keep the code clean and consistent, we use `pylint` and `black`: In order to keep the code clean and consistent, we use `pylint` and `black`:
``` ```
pip install black pylint pip install black pylint
``` ```
### To run pylint: ### To run pylint (ignores build and virtualenv):
``` ```
pylint tools/ --ignore=build,tests,bin,lib pylint tools/ --ignore=build,bin,lib
``` ```
### To check code formatting without rewriting files: ### To check code formatting without rewriting files:

View File

@ -1,5 +1,4 @@
import os import os
import pytest
from typing import List, TextIO from typing import List, TextIO
from isledecomp.parser import find_code_blocks from isledecomp.parser import find_code_blocks
from isledecomp.parser.util import CodeBlock from isledecomp.parser.util import CodeBlock
@ -11,7 +10,7 @@ def sample_file(filename: str) -> TextIO:
"""Wrapper for opening the samples from the directory that does not """Wrapper for opening the samples from the directory that does not
depend on the cwd where we run the test""" depend on the cwd where we run the test"""
full_path = os.path.join(SAMPLE_DIR, filename) full_path = os.path.join(SAMPLE_DIR, filename)
return open(full_path, "r") return open(full_path, "r", encoding="utf-8")
def code_blocks_are_sorted(blocks: List[CodeBlock]) -> bool: def code_blocks_are_sorted(blocks: List[CodeBlock]) -> bool:

View File

@ -1,6 +1,6 @@
import pytest
from collections import namedtuple from collections import namedtuple
from typing import List from typing import List
import pytest
from isledecomp.parser.util import ( from isledecomp.parser.util import (
is_blank_or_comment, is_blank_or_comment,
match_offset_comment, match_offset_comment,
@ -69,14 +69,14 @@ def test_is_blank_or_comment(line: str, expected: bool):
] ]
@pytest.mark.parametrize("match, exact, line", offset_comment_samples) @pytest.mark.parametrize("match, _, line", offset_comment_samples)
def test_offset_match(line: str, match: bool, exact): def test_offset_match(line: str, match: bool, _):
did_match = match_offset_comment(line) is not None did_match = match_offset_comment(line) is not None
assert did_match is match assert did_match is match
@pytest.mark.parametrize("match, exact, line", offset_comment_samples) @pytest.mark.parametrize("_, exact, line", offset_comment_samples)
def test_exact_offset_comment(line: str, exact: bool, match): def test_exact_offset_comment(line: str, exact: bool, _):
assert is_exact_offset_comment(line) is exact assert is_exact_offset_comment(line) is exact