-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1235: Pytest migration r=hgrecco a=hgrecco - [x] Closes #947 (insert issue number) - [x] Executed ``pre-commit run --all-files`` with no errors - [x] The change is fully covered by automated unit tests - [x] Documented in docs/ as appropriate - [x] Added an entry to the CHANGES file Co-authored-by: Hernan <[email protected]> Co-authored-by: Hernan Grecco <[email protected]>
- Loading branch information
Showing
29 changed files
with
3,237 additions
and
3,109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# pytest fixtures | ||
|
||
import io | ||
|
||
import pytest | ||
|
||
import pint | ||
|
||
|
||
@pytest.fixture | ||
def registry_empty(): | ||
return pint.UnitRegistry(None) | ||
|
||
|
||
@pytest.fixture | ||
def registry_tiny(): | ||
return pint.UnitRegistry( | ||
io.StringIO( | ||
""" | ||
yocto- = 1e-24 = y- | ||
zepto- = 1e-21 = z- | ||
atto- = 1e-18 = a- | ||
femto- = 1e-15 = f- | ||
pico- = 1e-12 = p- | ||
nano- = 1e-9 = n- | ||
micro- = 1e-6 = µ- = u- | ||
milli- = 1e-3 = m- | ||
centi- = 1e-2 = c- | ||
deci- = 1e-1 = d- | ||
deca- = 1e+1 = da- = deka- | ||
hecto- = 1e2 = h- | ||
kilo- = 1e3 = k- | ||
mega- = 1e6 = M- | ||
giga- = 1e9 = G- | ||
tera- = 1e12 = T- | ||
peta- = 1e15 = P- | ||
exa- = 1e18 = E- | ||
zetta- = 1e21 = Z- | ||
yotta- = 1e24 = Y- | ||
meter = [length] = m = metre | ||
second = [time] = s = sec | ||
angstrom = 1e-10 * meter = Å = ångström = Å | ||
minute = 60 * second = min | ||
""" | ||
) | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def func_registry(): | ||
return pint.UnitRegistry() | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def class_registry(): | ||
"""Only use for those test that do not modify the registry.""" | ||
return pint.UnitRegistry() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def sess_registry(): | ||
"""Only use for those test that do not modify the registry.""" | ||
return pint.UnitRegistry() | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def class_tiny_app_registry(): | ||
ureg_bak = pint.get_application_registry() | ||
ureg = pint.UnitRegistry(None) | ||
ureg.define("foo = []") | ||
ureg.define("bar = foo / 2") | ||
pint.set_application_registry(ureg) | ||
assert pint.get_application_registry() is ureg | ||
yield ureg | ||
pint.set_application_registry(ureg_bak) |
Oops, something went wrong.