Skip to content

Commit b1c8b61

Browse files
authored
spec testing (#102)
* 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
1 parent 6ec979e commit b1c8b61

51 files changed

Lines changed: 23477 additions & 38 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yml

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,31 @@ jobs:
1111
matrix:
1212
python-version: ["3.10", "3.11", "3.12", "3.13"]
1313
steps:
14-
- uses: actions/checkout@v4
15-
- name: Setup Graphviz
16-
uses: ts-graphviz/setup-graphviz@v2
17-
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v5
19-
id: cpython3
20-
with:
21-
python-version: ${{ matrix.python-version }}
22-
cache: pip
23-
cache-dependency-path: requirements.txt
24-
allow-prereleases: true
25-
- run: pip install -r requirements.txt
26-
- run: pip install black ruff pytest pytest-cov
27-
- run: ruff check .
28-
- name: Run mypy if on 3.12, pytype otherwise
29-
run: |
30-
if [[ '${{ steps.cpython3.outputs.python-version }}' == *"3.11"* ]]; then
31-
pip install pytype
32-
pytype -j auto graphviz2drawio
33-
else
34-
echo "pytype does not support >= 3.12: https://github.com/google/pytype/issues/1475"
35-
pip install mypy
36-
mypy graphviz2drawio --ignore-missing-imports
37-
fi
38-
- uses: psf/black@stable
39-
with:
40-
options: "--check --verbose"
41-
- run: pytest --cov
42-
- name: Run main script
43-
run: |
44-
python3 -m graphviz2drawio test/directed/hello.gv.txt
45-
test -f test/directed/hello.gv.xml
14+
- uses: actions/checkout@v4
15+
- name: Setup Graphviz
16+
uses: ts-graphviz/setup-graphviz@v2
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v5
19+
id: cpython3
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
cache: pip
23+
cache-dependency-path: requirements.txt
24+
allow-prereleases: true
25+
- run: pip install -r requirements.txt
26+
- run: pip install black ruff pytest pytest-cov
27+
- run: ruff check .
28+
- name: Run mypy if on 3.12, pytype otherwise
29+
run: |
30+
if [[ '${{ steps.cpython3.outputs.python-version }}' == 3.11* ]]; then
31+
pip install pytype
32+
pytype -j auto graphviz2drawio
33+
else
34+
echo "pytype does not support >= 3.12: https://github.com/google/pytype/issues/1475"
35+
pip install mypy
36+
mypy graphviz2drawio --ignore-missing-imports
37+
fi
38+
- uses: psf/black@stable
39+
with:
40+
options: "--check --verbose"
41+
- run: pytest --cov

.github/workflows/spec_test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Spec Test
2+
on: push
3+
4+
permissions:
5+
contents: read
6+
7+
jobs:
8+
spec-test:
9+
runs-on: macos-13
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Set up Python
13+
uses: actions/setup-python@v5
14+
id: cpython3
15+
with:
16+
python-version: "3.12"
17+
cache: pip
18+
cache-dependency-path: requirements.txt
19+
- run: brew install graphviz
20+
- run: pip install -r requirements.txt
21+
- name: Run specs tests script
22+
run: |
23+
mkdir tmp_out
24+
./test_specs.sh test/ specs/ tmp_out/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5+
tmp_out/
56

67
# C extensions
78
*.so

.typos.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[files]
2-
extend-exclude = ["test/**"]
2+
extend-exclude = ["test/**", "specs/**"]

generate_specs.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Check if the correct number of arguments is provided
4+
if [ "$#" -ne 2 ]; then
5+
echo "Usage: $0 <source_directory> <specs_directory>"
6+
exit 1
7+
fi
8+
9+
# Assign arguments to variables
10+
source_dir="$1"
11+
specs_dir="$2"
12+
13+
# Ensure source_dir doesn't end with a slash
14+
source_dir="${source_dir%/}"
15+
16+
# Find all .gv.txt files in the source directory and its subdirectories
17+
find "$source_dir" -type f -name "*.gv.txt" | while read -r file; do
18+
# Get the relative path of the file from the source directory
19+
rel_path="${file#$source_dir/}"
20+
21+
# Create the output filename, preserving the directory structure
22+
output_file="$specs_dir/${rel_path%.gv.txt}.xml"
23+
24+
# Create the directory structure if it doesn't exist
25+
mkdir -p "$(dirname "$output_file")"
26+
27+
# Run the command
28+
python3 -m graphviz2drawio "$file" -o "$output_file"
29+
30+
echo "Processed: $file -> $output_file"
31+
done
32+
33+
echo "All .gv.txt files have been processed."

graphviz2drawio/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def _convert_file(to_convert: TextIOWrapper, program: str, outfile: str | None)
3535
print(output)
3636
return
3737

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

4143

0 commit comments

Comments
 (0)