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

ci: test on windows and mac #33

Merged
merged 6 commits into from
Dec 27, 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
6 changes: 5 additions & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ on:

jobs:
benchmark:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
Expand Down
36 changes: 29 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,48 @@ on:
branches: [ "main" ]

jobs:
test:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install Hatch
uses: pypa/hatch@install
- name: Check types with mypy
run: hatch run mypy --install-types --non-interactive playa
test:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install Hatch
uses: pypa/hatch@install
- name: Run tests
run: hatch test --cover -py 3.9
- name: Install ghostscript
run: sudo apt update && sudo apt install ghostscript
thirdparty-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v5
- name: Install Hatch
uses: pypa/hatch@install
- name: Run pdf.js testsuite
run: |
hatch run pytest -k pdf.js
- name: Run pdfplumber tests
run: |
sudo apt update && sudo apt install ghostscript
cd samples/3rdparty/pdfplumber
python -m venv venv
SETUPTOOLS_SCM_PRETEND_VERSION=0.2.5 venv/bin/pip install -e ../../..
Expand Down
52 changes: 26 additions & 26 deletions benchmarks/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,19 @@ def bench_mmap():

from playa.parser import Lexer

with tempfile.NamedTemporaryFile() as tf:
with tempfile.TemporaryFile(mode="w+b") as tf:
runs = 100
with open(tf.name, "wb") as outfh:
outfh.write(DATA * runs)
with open(tf.name, "rb") as infh:
start = time.time()
mapping = mmap.mmap(infh.fileno(), 0, access=mmap.ACCESS_READ)
parser = Lexer(mapping)
_ = list(parser)
print(
"PLAYA Lexer (mmap): %fms / run"
% ((time.time() - start) / runs * 1000),
)
tf.write(DATA * runs)
tf.flush()
tf.seek(0, 0)
start = time.time()
mapping = mmap.mmap(tf.fileno(), 0, access=mmap.ACCESS_READ)
parser = Lexer(mapping)
_ = list(parser)
print(
"PLAYA Lexer (mmap): %fms / run"
% ((time.time() - start) / runs * 1000),
)


def bench_playa():
Expand Down Expand Up @@ -341,21 +341,21 @@ def bench_pdfminer():
"pdfminer.six Lexer (BytesIO): %fms / run"
% ((time.time() - start) / runs * 1000),
)
with tempfile.NamedTemporaryFile() as tf:
with tempfile.TemporaryFile(mode="w+b") as tf:
runs = 100
with open(tf.name, "wb") as outfh:
outfh.write(DATA * runs)
with open(tf.name, "rb") as infh:
parser = PSBaseParser(infh)
while True:
try:
_ = parser.nexttoken()
except PSEOF:
break
print(
"pdfminer.six Lexer (BinaryIO): %fms / run"
% ((time.time() - start) / runs * 1000),
)
tf.write(DATA * runs)
tf.flush()
tf.seek(0, 0)
parser = PSBaseParser(tf)
while True:
try:
_ = parser.nexttoken()
except PSEOF:
break
print(
"pdfminer.six Lexer (BinaryIO): %fms / run"
% ((time.time() - start) / runs * 1000),
)
runs = 20
start = time.time()
for _ in range(runs):
Expand Down
2 changes: 1 addition & 1 deletion tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ALLPDFS.extend(PLUMBERS.glob("*.pdf"))
PDFJS = TESTDIR / "3rdparty" / "pdf.js" / "test"
try:
with open(PDFJS / "test_manifest.json") as infh:
with open(PDFJS / "test_manifest.json", encoding="utf-8") as infh:
manifest = json.load(infh)
for entry in manifest:
path = PDFJS / entry["file"]
Expand Down
Loading