Skip to content

Commit 7cfa503

Browse files
committed
Enabling 3.12, using pytest-benchmark
1 parent ac5afdd commit 7cfa503

File tree

4 files changed

+57
-101
lines changed

4 files changed

+57
-101
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
python-version:
18+
- "3.12"
1819
- "3.11"
1920
- "3.10"
2021
- "3.9"

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ dev =
7777
pydantic>2
7878
pytest
7979
pytest-asyncio
80+
pytest-benchmark
8081
pytest-cov
8182
pytest-xdist
8283
snakeviz
@@ -92,7 +93,6 @@ dev =
9293
omit =
9394
src/measured/_parser.py
9495
src/measured/pytest.py
95-
tests/performance_harness.py
9696

9797
[isort]
9898
profile = black

tests/performance_harness.py

Lines changed: 0 additions & 100 deletions
This file was deleted.

tests/test_performance.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from pytest_benchmark.fixture import BenchmarkFixture
2+
3+
from measured import One, Quantity
4+
from measured.astronomical import JulianYear
5+
from measured.si import Ampere, Meter, Ohm, Second, Volt
6+
from measured.us import Ounce, Ton
7+
8+
9+
def test_quantity_construction(benchmark: BenchmarkFixture) -> None:
10+
def quantity_construction() -> Quantity:
11+
return Quantity(1000001, Meter)
12+
13+
result = benchmark(quantity_construction)
14+
15+
assert result == Quantity(1000001, Meter)
16+
17+
18+
def test_low_dimensional_equality(benchmark: BenchmarkFixture) -> None:
19+
a = Quantity(1000, Meter)
20+
b = Quantity(1000, Meter)
21+
22+
def low_dimensional_equality() -> bool:
23+
return bool(a == b)
24+
25+
assert benchmark(low_dimensional_equality) is True
26+
27+
28+
def test_high_dimensional_equality(benchmark: BenchmarkFixture) -> None:
29+
a = Quantity(1000, Ohm)
30+
b = Quantity(1000, Ohm)
31+
32+
def high_dimensional_equality() -> bool:
33+
return bool(a == b)
34+
35+
assert benchmark(high_dimensional_equality) is True
36+
37+
38+
def test_computing_resistances(benchmark: BenchmarkFixture) -> None:
39+
a = Quantity(1000, Ampere)
40+
v = Quantity(1000, Volt)
41+
42+
def computing_resistances() -> Quantity:
43+
return v / a
44+
45+
assert benchmark(computing_resistances) == Quantity(1, Ohm)
46+
47+
48+
def test_complicated_conversions(benchmark: BenchmarkFixture) -> None:
49+
o = Quantity(1000, Ounce / (JulianYear * Ampere))
50+
t = Quantity(1000, Ton / (Second * Ampere))
51+
52+
def divide() -> Quantity:
53+
return (t / o).in_unit(One)
54+
55+
assert benchmark(divide).unit == One

0 commit comments

Comments
 (0)