Skip to content

Commit

Permalink
Fix tests for default preferred units (#1868)
Browse files Browse the repository at this point in the history
* TST: fix ureg attribute default_preferred_units and set autoconvert_to_preferred=True in test of autoconvert

* TST: Use class ureg so both regular and _DEFAULT_REGISTRY are tested

* CNF: Add mip install to github ci run to test to_preferred

---------

Co-authored-by: Dana Nadler <[email protected]>
  • Loading branch information
dcnadler and Dana Nadler authored Dec 3, 2023
1 parent 37127e1 commit 04cc929
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- python-version: 3.9
numpy: "numpy"
uncertainties: "uncertainties"
extras: "sparse xarray netCDF4 dask[complete]==2023.4.0 graphviz babel==2.8"
extras: "sparse xarray netCDF4 dask[complete]==2023.4.0 graphviz babel==2.8 mip>=1.13"
runs-on: ubuntu-latest

env:
Expand Down
17 changes: 9 additions & 8 deletions pint/testsuite/test_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ def test_convert(self):

@helpers.requires_mip
def test_to_preferred(self):
ureg = UnitRegistry()
Q_ = ureg.Quantity
ureg = self.ureg
Q_ = self.Q_

ureg.define("pound_force_per_square_foot = 47.8803 pascals = psf")
ureg.define("pound_mass = 0.45359237 kg = lbm")
Expand Down Expand Up @@ -412,9 +412,9 @@ def test_to_preferred(self):

@helpers.requires_mip
def test_to_preferred_registry(self):
ureg = UnitRegistry()
Q_ = ureg.Quantity
ureg.preferred_units = [
ureg = self.ureg
Q_ = self.Q_
ureg.default_preferred_units = [
ureg.m, # distance L
ureg.kg, # mass M
ureg.s, # duration T
Expand All @@ -427,9 +427,10 @@ def test_to_preferred_registry(self):

@helpers.requires_mip
def test_autoconvert_to_preferred(self):
ureg = UnitRegistry()
Q_ = ureg.Quantity
ureg.preferred_units = [
ureg = self.ureg
Q_ = self.Q_
ureg.autoconvert_to_preferred = True
ureg.default_preferred_units = [
ureg.m, # distance L
ureg.kg, # mass M
ureg.s, # duration T
Expand Down

0 comments on commit 04cc929

Please sign in to comment.