aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-05-27 13:52:20 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-05-27 13:52:20 +0200
commit94e8537430ab7496e4b8e697581d65b06cf8b979 (patch)
tree400ddf6deac24ce3b21a0678bfe9afb5f7f8a1e9
parent0259c6f907875b54e5d1df4bc89efa1c293d2812 (diff)
downloadee-python-94e8537430ab7496e4b8e697581d65b06cf8b979.tar.gz
ee-python-94e8537430ab7496e4b8e697581d65b06cf8b979.tar.bz2
ee-python-94e8537430ab7496e4b8e697581d65b06cf8b979.tar.xz
ee-python-94e8537430ab7496e4b8e697581d65b06cf8b979.zip
EeVal: Supporting omega symbol in addition to ohm symbol (which are
usually graphically equal).
-rw-r--r--src/ee/__init__.py4
-rw-r--r--src/ee/formatting/__init__.py2
-rw-r--r--test/test_EeVal.py51
3 files changed, 31 insertions, 26 deletions
diff --git a/src/ee/__init__.py b/src/ee/__init__.py
index 06c5aab..ea887b1 100644
--- a/src/ee/__init__.py
+++ b/src/ee/__init__.py
@@ -36,7 +36,9 @@ power_type = EeValType("W", [])
@total_ordering
class EeVal(object):
units = ['F',
- 'Ohm', '\u2126', # Ohm symbol
+ 'Ohm',
+ '\u03a9', # Ohm, the greek (upper case) letter
+ '\u2126', # Ohm symbol, deprecated from unicode
'H']
exponents = {
'f': -15,
diff --git a/src/ee/formatting/__init__.py b/src/ee/formatting/__init__.py
index d32f7f9..073d533 100644
--- a/src/ee/formatting/__init__.py
+++ b/src/ee/formatting/__init__.py
@@ -14,7 +14,7 @@ class ESeries(object):
def __init__(self, series):
self.series = series
- def closest(self, value, round_direction = ROUND_CLOSEST):
+ def closest(self, value, round_direction=ROUND_CLOSEST):
if round_direction != ESeries.ROUND_CLOSEST:
raise NotImplementedError("Only closest rounding is implemented for now")
e = math.floor(math.log10(value))
diff --git a/test/test_EeVal.py b/test/test_EeVal.py
index 6d4032f..f311aa6 100644
--- a/test/test_EeVal.py
+++ b/test/test_EeVal.py
@@ -3,31 +3,31 @@ from ee import EeVal
@pytest.mark.parametrize("s, num_value, str_value, unit", [
- # ("0", 0, "0", None),
- # ("0 k", 0, "0", None),
- # ("1", 1, "1", None),
- # ("1e-3", 0.001, "1 m", None),
- # ("1e3", 1000, "1 k", None),
- # ("4.7e3", 4700, "4.7 k", None),
+ ("0", 0, "0", None),
+ ("0 k", 0, "0", None),
+ ("1", 1, "1", None),
+ ("1e-3", 0.001, "1 m", None),
+ ("1e3", 1000, "1 k", None),
+ ("4.7e3", 4700, "4.7 k", None),
("4.e3", 4000, "4 k", None),
- # ("10", 10, "10", None),
- # ("10k", 10 * 1000, "10 k", None),
- # ("10 k", 10 * 1000, "10 k", None),
- # ("10 k", 10 * 1000, "10 k", None),
- # ("1000 m", 1, "1", None),
- # ("100 m", 0.1, "100 m", None),
- # ("100 n", 0.0000001, "100 n", None),
- # ("1 m", 0.001, "1 m", None),
- # ("1 u", 0.000001, "1 u", None),
- # ("0.1 u", 0.0000001, "100 n", None),
- # (".1 u", 0.0000001, "100 n", None),
- # ("4.7 u", 0.0000047, "4.7 u", None),
- # ("1 µ", 0.000001, "1 u", None),
- # ("1 n", 0.000000001, "1 n", None),
- # ("10 n", 0.00000001, "10 n", None),
- # ("1p", 1e-12, "1 p", None),
- # ("0.8p", 8e-13, "0.8 p", None),
- # ("0.008p", 8e-15, "0.008 p", None),
+ ("10", 10, "10", None),
+ ("10k", 10 * 1000, "10 k", None),
+ ("10 k", 10 * 1000, "10 k", None),
+ ("10 k", 10 * 1000, "10 k", None),
+ ("1000 m", 1, "1", None),
+ ("100 m", 0.1, "100 m", None),
+ ("100 n", 0.0000001, "100 n", None),
+ ("1 m", 0.001, "1 m", None),
+ ("1 u", 0.000001, "1 u", None),
+ ("0.1 u", 0.0000001, "100 n", None),
+ (".1 u", 0.0000001, "100 n", None),
+ ("4.7 u", 0.0000047, "4.7 u", None),
+ ("1 µ", 0.000001, "1 u", None),
+ ("1 n", 0.000000001, "1 n", None),
+ ("10 n", 0.00000001, "10 n", None),
+ ("1p", 1e-12, "1 p", None),
+ ("0.8p", 8e-13, "0.8 p", None),
+ ("0.008p", 8e-15, "0.008 p", None),
])
def test_basic(s, num_value, str_value, unit):
num_value = float(num_value)
@@ -45,6 +45,9 @@ def test_basic(s, num_value, str_value, unit):
("10n F", "10 nF", "F"),
("10 n F", "10 nF", "F"),
("4.7 n F", "4.7 nF", "F"),
+ ("10Ω", "10 Ω", "Ω"),
+ ("10 Ω", "10 Ω", "Ω"),
+ ("10 Ohm", "10 Ohm", "Ohm"),
])
def test_units(s, str_value, unit):
v = EeVal(s)