Skip to content

Commit

Permalink
Merge pull request #126 from angelcaru/master
Browse files Browse the repository at this point in the history
Run tests and linting on CI
  • Loading branch information
Almas-Ali authored May 1, 2024
2 parents e2d0f41 + ed7e1ed commit 182f45b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: CI
on: [push, pull_request]
jobs:
everything:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: python3 -m pip install mypy ruff
- run: python3 test.py full


45 changes: 43 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def run_test(test: str) -> Output:


def run_tests(directory: str = "tests") -> int:
mypy = subprocess.Popen(["mypy", "."], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=dict(**os.environ, MYPY_FORCE_COLOR="1"))
mypy = subprocess.Popen(
["mypy", "."], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=dict(**os.environ, MYPY_FORCE_COLOR="1")
)

failed_tests = []
for test in os.listdir(directory):
Expand Down Expand Up @@ -65,7 +67,9 @@ def run_tests(directory: str = "tests") -> int:
for test in failed_tests:
print(f" {test!r}")

print("Waiting on mypy...")
print("--------------")
print(" mypy . ")
print("--------------")
mypy.wait()
assert mypy.stdout is not None
assert mypy.stderr is not None
Expand Down Expand Up @@ -101,6 +105,7 @@ def usage(program_name: str, stream: IO[str]) -> None:
run - Run tests
record - Record output of tests
diff <test.rn> - Show diff between expected and actual output
full - Same as `{program_name} run` + `make lint`
""",
file=stream,
)
Expand All @@ -122,6 +127,42 @@ def main(argv: list[str]) -> int:
return run_tests()
case "record":
return record_tests()
case "full":
env = dict(**os.environ, FORCE_COLOR="1")
ruff_format = subprocess.Popen(
["ruff", "format", "--check", "."], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
)
ruff_check = subprocess.Popen(
["ruff", "check", "."], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
)

test_returncode = run_tests()

format_ret = ruff_format.wait()
check_ret = ruff_check.wait()

print("---------------------")
print("ruff format --check .")
print("---------------------")
assert ruff_format.stdout is not None and ruff_format.stderr is not None
sys.stdout.buffer.write(ruff_format.stdout.read())
sys.stderr.buffer.write(ruff_format.stderr.read())
print("---------------------")
print(" ruff check . ")
print("---------------------")
assert ruff_check.stdout is not None and ruff_check.stderr is not None
sys.stdout.buffer.write(ruff_check.stdout.read())
sys.stderr.buffer.write(ruff_check.stderr.read())

if test_returncode == 0 and format_ret == 0 and check_ret == 0:
print("Full test succeeded with no errors!")
return 0
else:
if format_ret != 0:
print("ERROR: ruff format failed", file=sys.stderr)
if check_ret != 0:
print("ERROR: ruff check failed", file=sys.stderr)
return 1
case "diff":
if len(argv) < 1:
usage(program_name, sys.stderr)
Expand Down

0 comments on commit 182f45b

Please sign in to comment.