Skip to content

Commit

Permalink
More detailed return values of is_compliant() and is_exempt().
Browse files Browse the repository at this point in the history
  • Loading branch information
zimolzak committed May 8, 2021
1 parent 26bfba7 commit 5ed43a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions fcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
def is_compliant(watts, t_average, duty, dbi, ft, mhz, ground_reflections, controlled):
"""Return a boolean and a string."""
meters = ft * 0.3048
if is_exempt(watts, meters, mhz): # fixme - might have to check power vs ERP vs EIRP
return True, 'exemption'
ex, method = is_exempt(watts, meters, mhz) # fixme - might have to check power vs ERP vs EIRP
if ex:
return True, method
else:
report = rf_evaluation_report(watts, t_average, duty, dbi, ft, mhz, ground_reflections)
if controlled:
Expand Down Expand Up @@ -111,9 +112,9 @@ def is_exempt(watts, meters, mhz):
"""Return boolean."""
try:
threshold, method = exempt_watts_generic(meters, mhz)
return watts < threshold # fixme - consider returning tuple of (True, method)
return watts < threshold, method
except RFEvaluationError:
return False
return False, 'nearfield'
# Do not catch general ValueError, which means mhz may be out of range.


Expand Down
18 changes: 9 additions & 9 deletions test_fcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def test_is_compliant():
w = mw / 1000
ft = cm / 30.48
mhz = ghz * 1000
assert fcc.is_compliant(w * 0.9, t, du, db, ft, mhz, gr, co) == (True, 'exemption')
assert fcc.is_compliant(w * 0.9, t, du, db, ft, mhz, gr, co) == (True, 'SAR')
# Shouldn't test w * 1.1, because some powers above MPE exemption will pass is_compliant() by eval.
n += 1
for meters, mhz in mpe_usable_values():
# valid MPE thresholds
w = fcc.exempt_watts_mpe(meters, mhz)
ft = meters / 0.3048
assert fcc.is_compliant(w * 0.9, t, du, db, ft, mhz, gr, co) == (True, 'exemption')
assert fcc.is_compliant(w * 0.9, t, du, db, ft, mhz, gr, co) == (True, 'MPE')
n += 1
print("\n Looped %d tests of is_compliant()." % n, end='')

Expand Down Expand Up @@ -142,31 +142,31 @@ def test_effective_isotropic_radiated_power():
def test_is_exempt():
n = 0
# watts, m, mhz are arguments to is_exempt()
assert fcc.is_exempt(5, 1, 420)
assert fcc.is_exempt(5, 0.1, 420) is False
assert fcc.is_exempt(5, 1, 420) == (True, 'MPE')
assert fcc.is_exempt(5, 0.1, 420)[0] is False
with pytest.raises(ValueError):
fcc.is_exempt(5, 0.1, 1234567890)
for ghz, cm, mw in fcc_table():
# valid SAR thresholds
w = mw / 1000
m = cm / 100
mhz = ghz * 1000
assert fcc.is_exempt(w * 0.9, m, mhz)
assert fcc.is_exempt(w * 1.1, m, mhz) is False
assert fcc.is_exempt(w * 0.9, m, mhz) == (True, 'SAR')
assert fcc.is_exempt(w * 1.1, m, mhz)[0] is False
n += 2
for meters, mhz, why_exception in mpe_exception_values():
# known NON-exemption
if why_exception == 'freq':
with pytest.raises(ValueError):
fcc.is_exempt(0.42, meters, mhz) # watts doesn't matter if freq invalid
else:
assert fcc.is_exempt(0.42, meters, mhz) is False # watts don't matter in near field
assert fcc.is_exempt(0.42, meters, mhz)[0] is False # watts don't matter in near field
n += 1
for meters, mhz in mpe_usable_values():
# valid MPE thresholds
w = fcc.exempt_watts_mpe(meters, mhz)
assert fcc.is_exempt(w * 0.9, meters, mhz)
assert fcc.is_exempt(w * 1.1, meters, mhz) is False
assert fcc.is_exempt(w * 0.9, meters, mhz) == (True, 'MPE')
assert fcc.is_exempt(w * 1.1, meters, mhz)[0] is False
n += 2
print("\n Looped %d tests of is_exempt()." % n, end='')

Expand Down

0 comments on commit 5ed43a9

Please sign in to comment.