Skip to content

Commit

Permalink
spec testing (#102)
Browse files Browse the repository at this point in the history
* spec testing

* run spec tests in CI

* spec tests on mac runner

* brew install graphviz

* ignore ID's in spec comparison

* shape/style update for specs

* test on python 3.12 on macos 13
  • Loading branch information
hbmartin authored Oct 5, 2024
1 parent 6ec979e commit b1c8b61
Show file tree
Hide file tree
Showing 51 changed files with 23,477 additions and 38 deletions.
60 changes: 28 additions & 32 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,31 @@ jobs:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
id: cpython3
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: requirements.txt
allow-prereleases: true
- run: pip install -r requirements.txt
- run: pip install black ruff pytest pytest-cov
- run: ruff check .
- name: Run mypy if on 3.12, pytype otherwise
run: |
if [[ '${{ steps.cpython3.outputs.python-version }}' == *"3.11"* ]]; then
pip install pytype
pytype -j auto graphviz2drawio
else
echo "pytype does not support >= 3.12: https://github.com/google/pytype/issues/1475"
pip install mypy
mypy graphviz2drawio --ignore-missing-imports
fi
- uses: psf/black@stable
with:
options: "--check --verbose"
- run: pytest --cov
- name: Run main script
run: |
python3 -m graphviz2drawio test/directed/hello.gv.txt
test -f test/directed/hello.gv.xml
- uses: actions/checkout@v4
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
id: cpython3
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: requirements.txt
allow-prereleases: true
- run: pip install -r requirements.txt
- run: pip install black ruff pytest pytest-cov
- run: ruff check .
- name: Run mypy if on 3.12, pytype otherwise
run: |
if [[ '${{ steps.cpython3.outputs.python-version }}' == 3.11* ]]; then
pip install pytype
pytype -j auto graphviz2drawio
else
echo "pytype does not support >= 3.12: https://github.com/google/pytype/issues/1475"
pip install mypy
mypy graphviz2drawio --ignore-missing-imports
fi
- uses: psf/black@stable
with:
options: "--check --verbose"
- run: pytest --cov
24 changes: 24 additions & 0 deletions .github/workflows/spec_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Spec Test
on: push

permissions:
contents: read

jobs:
spec-test:
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
id: cpython3
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements.txt
- run: brew install graphviz
- run: pip install -r requirements.txt
- name: Run specs tests script
run: |
mkdir tmp_out
./test_specs.sh test/ specs/ tmp_out/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
tmp_out/

# C extensions
*.so
Expand Down
2 changes: 1 addition & 1 deletion .typos.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[files]
extend-exclude = ["test/**"]
extend-exclude = ["test/**", "specs/**"]
33 changes: 33 additions & 0 deletions generate_specs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <source_directory> <specs_directory>"
exit 1
fi

# Assign arguments to variables
source_dir="$1"
specs_dir="$2"

# Ensure source_dir doesn't end with a slash
source_dir="${source_dir%/}"

# Find all .gv.txt files in the source directory and its subdirectories
find "$source_dir" -type f -name "*.gv.txt" | while read -r file; do
# Get the relative path of the file from the source directory
rel_path="${file#$source_dir/}"

# Create the output filename, preserving the directory structure
output_file="$specs_dir/${rel_path%.gv.txt}.xml"

# Create the directory structure if it doesn't exist
mkdir -p "$(dirname "$output_file")"

# Run the command
python3 -m graphviz2drawio "$file" -o "$output_file"

echo "Processed: $file -> $output_file"
done

echo "All .gv.txt files have been processed."
4 changes: 3 additions & 1 deletion graphviz2drawio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def _convert_file(to_convert: TextIOWrapper, program: str, outfile: str | None)
print(output)
return

pathlib.Path(outfile).write_text(output)
out_path = pathlib.Path(outfile)
out_path.parent.mkdir(parents=True, exist_ok=True)
out_path.write_text(output)
stderr.write("Converted file: " + outfile + "\n")


Expand Down
Loading

0 comments on commit b1c8b61

Please sign in to comment.