Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup utils tests #145

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,18 @@ jobs:
# This token is only used with the job's container, so it is safe to
# echo it here.
echo "AllSpice Hub token = $(cat .token)"
- name: Test with pytest
# If the test is running on a schedule, the purpose of the test is to
# ensure py-allspice isn't out of date with the current version of hub, so
# we'll ignore the casettes.
- name: Test with pytest without using casettes
if: ${{ github.event_name == 'schedule' }}
run: |
python -m pytest
python -m pytest --record-mode=rewrite
# Otherwise, we'll use the casettes to make the tests fast.
- name: Test with pytest using casettes
if: ${{ github.event_name != 'schedule' }}
run: |
python -m pytest --record-mode=none
- name: Check attribute types
# This script will re-generate the attribute types and check if they
# are different from the committed version. The formatter and linter
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"orcad",
"paramvariation",
"prjpcb",
"pytestconfig",
"recentupdate",
"reponame",
"schdoc"
Expand Down
5 changes: 4 additions & 1 deletion allspice/utils/list_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from ..apiobject import Repository
from ..exceptions import NotYetGeneratedException

SLEEP_FOR_GENERATED_JSON = 0.5
"""The amount of time to sleep between attempts to fetch generated JSON files."""

PCB_FOOTPRINT_ATTR_NAME = "PCB Footprint"
PART_REFERENCE_ATTR_NAME = "Part Reference"
REPETITIONS_REGEX = re.compile(r"Repeat\(\w+,(\d+),(\d+)\)")
Expand Down Expand Up @@ -219,7 +222,7 @@ def _fetch_generated_json(repo: Repository, file_path: str, ref: str) -> dict:
try:
return repo.get_generated_json(file_path, ref=ref)
except NotYetGeneratedException:
time.sleep(0.5)
time.sleep(SLEEP_FOR_GENERATED_JSON)

raise TimeoutError(f"Failed to fetch JSON for {file_path} after 5 attempts.")

Expand Down
8 changes: 5 additions & 3 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
libcst~=1.4.0
MonkeyType~=23.3
pdoc~=14.5
pytest-recording~=0.13
pytest~=8.2
ruff~=0.4
pdoc~=14.5
MonkeyType~=23.3
libcst~=1.4.0
syrupy~=4.6
Empty file added tests/__init__.py
Empty file.
Loading