Skip to content

Commit

Permalink
split core into smaller files (#237)
Browse files Browse the repository at this point in the history
Move some code from core.py into ops.py, formatting.py, and parsing.py. Since some of the moved code is part of the `AffineScalarFunc` class, it was refactored into functions of `cls` that can be imported back into core.py and called on `AffineScalarFunc`.
  • Loading branch information
andrewgsavage authored Jul 10, 2024
1 parent 1238d37 commit 3d2b16d
Show file tree
Hide file tree
Showing 5 changed files with 2,218 additions and 2,182 deletions.
13 changes: 7 additions & 6 deletions tests/test_uncertainties.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import uncertainties.core as uncert_core
from uncertainties.core import ufloat, AffineScalarFunc, ufloat_fromstr
from uncertainties import formatting
from uncertainties import umath
from helpers import (power_special_cases, power_all_cases, power_wrt_ref,numbers_close,
ufloats_close, compare_derivatives, uarrays_close)
Expand Down Expand Up @@ -1091,7 +1092,7 @@ def test_PDG_precision():
}

for (std_dev, result) in tests.items():
assert uncert_core.PDG_precision(std_dev) == result
assert formatting.PDG_precision(std_dev) == result

def test_repr():
'''Test the representation of numbers with uncertainty.'''
Expand Down Expand Up @@ -1706,21 +1707,21 @@ def test_custom_pretty_print_and_latex():

# We will later restore the defaults:
PREV_CUSTOMIZATIONS = {
var: getattr(uncert_core, var).copy()
var: getattr(formatting, var).copy()
for var in ['PM_SYMBOLS', 'MULT_SYMBOLS', 'GROUP_SYMBOLS']}

# Customizations:
for format in ["pretty-print", "latex"]:
uncert_core.PM_SYMBOLS[format] = u" ± "
uncert_core.MULT_SYMBOLS[format] = u"⋅"
uncert_core.GROUP_SYMBOLS[format] = ( "[", "]" )
formatting.PM_SYMBOLS[format] = u" ± "
formatting.MULT_SYMBOLS[format] = u"⋅"
formatting.GROUP_SYMBOLS[format] = ( "[", "]" )

assert u"{:P}".format(x) == u'[2.00 ± 0.10]⋅10⁻¹¹'
assert u"{:L}".format(x) == u'[2.00 ± 0.10] ⋅ 10^{-11}'

# We restore the defaults:
for (var, setting) in PREV_CUSTOMIZATIONS.items():
setattr(uncert_core, var, setting)
setattr(formatting, var, setting)

###############################################################################

Expand Down
Loading

0 comments on commit 3d2b16d

Please sign in to comment.