Skip to content

Commit

Permalink
fix pytest, to add more build_docs functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Luar <[email protected]>
  • Loading branch information
luarss committed Oct 29, 2024
1 parent e66b60a commit 3d2597c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
run: |
make format
make check
- name: Run test
working-directory: backend
run: |
make test
- name: Populate environment variables
run: |
cp backend/.env.example backend/.env
Expand Down
4 changes: 4 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ format:
check:
@. .venv/bin/activate && \
ruff check --fix

test:
@. .venv/bin/activate && \
pytest
9 changes: 9 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = false
docstring-code-line-length = "dynamic"

[tool.pytest.ini_options]
python_files = "test_*.py"
python_functions = "test_*"
log_format = "%(asctime)s %(levelname)s %(message)s"
log_date_format = "%Y-%m-%d %H:%M:%S"
log_level = "NOTSET"
log_cli = true
testpaths = "tests"
9 changes: 0 additions & 9 deletions backend/pytest.ini

This file was deleted.

96 changes: 47 additions & 49 deletions backend/tests/test_build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import logging
from dotenv import load_dotenv

# TODO: Fix this using setup.py/pyproject.toml file in backend dir.
# TODO: Remove E402 from ruff.toml.
backend_dir = os.path.join(os.path.dirname(__file__), '..')
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
load_dotenv()

from build_docs import (
purge_folders,
get_yosys_rtdocs,
get_yosys_docs_html,
get_opensta_docs,
clone_repo,
build_or_docs,
Expand Down Expand Up @@ -54,56 +52,56 @@ def test_get_yosys_rtdocs():
os.chdir(backend_dir)
yosys_version='0.36'
yosys_docs_count=283
get_yosys_rtdocs()
assert os.path.exists('data/rtdocs')
get_yosys_docs_html()
assert os.path.exists('data/html')

count = sum(len(files) for _, _, files in os.walk(f"data/rtdocs/yosyshq.readthedocs.io/projects/yosys/en/{yosys_version}"))
count = sum(len(files) for _, _, files in os.walk(f"data/html/yosys_docs/yosyshq.readthedocs.io/projects/yosys/en/{yosys_version}"))
assert count == yosys_docs_count, f"Expected {yosys_docs_count} files, got {count}"


def test_get_opensta_docs():
os.chdir(backend_dir)
get_opensta_docs()
assert os.path.exists('data/pdf/OpenSTA/OpenSTA_docs.pdf')


def test_clone_repo():
os.chdir(backend_dir)
clone_repo(
url = 'https://github.com/octocat/Hello-World.git',
commit_hash='7fd1a60b01f91b314f59955a4e4d4e80d8edf11d',
folder_name = 'Hello-World',
)
assert os.path.exists('README')


def test_build_or_docs():
os.chdir(backend_dir)
or_docs_count = 55

clone_repo(
url='https://github.com/The-OpenROAD-Project/OpenROAD.git',
commit_hash=os.getenv('OR_REPO_COMMIT', 'ffc5760f2df639cd184c40ceba253c7e02a006d5'),
folder_name='OpenROAD',
)
build_or_docs()
count = sum(len(files) for _, _, files in os.walk('data/markdown/OR_docs'))
assert count == or_docs_count, f"Expected {or_docs_count} files, got {count}"


def test_build_orfs_docs():
os.chdir(backend_dir)
orfs_docs_count = 27

clone_repo(
url='https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts.git',
commit_hash=os.getenv('ORFS_REPO_COMMIT', 'b94834df01cb58915bc0e8dabf85a314fbd8fb9e'),
folder_name='OpenROAD-flow-scripts',
)
build_orfs_docs()
count = sum(len(files) for _, _, files in os.walk('data/markdown/ORFS_docs'))
logging.info(count)
assert count == orfs_docs_count, f"Expected {orfs_docs_count} files, got {count}"
# def test_get_opensta_docs():
# os.chdir(backend_dir)
# get_opensta_docs()
# assert os.path.exists('data/pdf/OpenSTA/OpenSTA_docs.pdf')


# def test_clone_repo():
# os.chdir(backend_dir)
# clone_repo(
# url = 'https://github.com/octocat/Hello-World.git',
# commit_hash='7fd1a60b01f91b314f59955a4e4d4e80d8edf11d',
# folder_name = 'Hello-World',
# )
# assert os.path.exists('README')


# def test_build_or_docs():
# os.chdir(backend_dir)
# or_docs_count = 55

# clone_repo(
# url='https://github.com/The-OpenROAD-Project/OpenROAD.git',
# commit_hash=os.getenv('OR_REPO_COMMIT', 'ffc5760f2df639cd184c40ceba253c7e02a006d5'),
# folder_name='OpenROAD',
# )
# build_or_docs()
# count = sum(len(files) for _, _, files in os.walk('data/markdown/OR_docs'))
# assert count == or_docs_count, f"Expected {or_docs_count} files, got {count}"


# def test_build_orfs_docs():
# os.chdir(backend_dir)
# orfs_docs_count = 27

# clone_repo(
# url='https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts.git',
# commit_hash=os.getenv('ORFS_REPO_COMMIT', 'b94834df01cb58915bc0e8dabf85a314fbd8fb9e'),
# folder_name='OpenROAD-flow-scripts',
# )
# build_orfs_docs()
# count = sum(len(files) for _, _, files in os.walk('data/markdown/ORFS_docs'))
# logging.info(count)
# assert count == orfs_docs_count, f"Expected {orfs_docs_count} files, got {count}"


def test_teardown():
Expand Down

0 comments on commit 3d2597c

Please sign in to comment.