Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
scottprahl committed Apr 30, 2024
1 parent b4bb77b commit 5192fad
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
1 change: 1 addition & 0 deletions tests/test_all_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
notebooks.sort()
ids = [str(n) for n in notebooks]


@pytest.mark.parametrize("notebook", notebooks, ids=ids)
def test_run_notebook(notebook):
"""Read and execute notebook
Expand Down
6 changes: 4 additions & 2 deletions tests/test_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
import numpy as np
from iadpython import Sphere, Port


class TestPort(unittest.TestCase):
"""Unit tests for the Port class."""

def setUp(self):
"""Set up test conditions for Port tests."""
d_sample = 25 # 20 mm sample port
d_sphere = 200 # 200 mm diameter sphere
R = d_sphere /2
R = d_sphere / 2
d_port = 20
uru_port = 0.5
self.sphere = Sphere(d_sphere, d_sample) #
self.sphere = Sphere(d_sphere, d_sample)
self.sphere.z = R
self.port = Port(self.sphere, d_port, uru=uru_port, z=R) # Example port

Expand Down Expand Up @@ -51,5 +52,6 @@ def test_uniform_01(self):
x, y, z = self.port.uniform()
self.assertTrue(self.port.hit(), "Hit detection is incorrect")


if __name__ == '__main__':
unittest.main()
22 changes: 17 additions & 5 deletions tests/test_rxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@

"""Tests for NIST reflectance data."""

import os
import unittest
import iadpython

# Get the directory of the current test file
test_dir = os.path.dirname(os.path.abspath(__file__))

# Path to the data directory relative to the test file
data_dir = os.path.join(test_dir, 'data')


class TestRXT(unittest.TestCase):
"""RXT files data."""

def test_rxt_01(self):
"""Verify m_r measurements read correctly."""
exp = iadpython.read_rxt('./tests/data/basic-A.rxt')
filename = os.path.join(data_dir, 'basic-A.rxt')
exp = iadpython.read_rxt(filename)
self.assertAlmostEqual(exp.m_r[0], 0.299262, delta=1e-5)
self.assertAlmostEqual(exp.m_r[-1], 0.09662, delta=1e-5)
self.assertIsNone(exp.m_t)
Expand All @@ -21,7 +29,8 @@ def test_rxt_01(self):

def test_rxt_02(self):
"""Verify m_r and m_t measurements read correctly."""
exp = iadpython.read_rxt('./tests/data/basic-B.rxt')
filename = os.path.join(data_dir, 'basic-B.rxt')
exp = iadpython.read_rxt(filename)
self.assertAlmostEqual(exp.m_r[0], 0.51485, delta=1e-5)
self.assertAlmostEqual(exp.m_t[0], 0.19596, delta=1e-5)
self.assertAlmostEqual(exp.m_r[-1], 0.44875, delta=1e-5)
Expand All @@ -31,7 +40,8 @@ def test_rxt_02(self):

def test_rxt_03(self):
"""Verify m_r, m_t, and m_u measurements read correctly."""
exp = iadpython.read_rxt('./tests/data/basic-C.rxt')
filename = os.path.join(data_dir, 'basic-C.rxt')
exp = iadpython.read_rxt(filename)
self.assertAlmostEqual(exp.m_r[0], 0.18744, delta=1e-5)
self.assertAlmostEqual(exp.m_t[0], 0.57620, delta=1e-5)
self.assertAlmostEqual(exp.m_u[0], 0.00560, delta=1e-5)
Expand All @@ -42,7 +52,8 @@ def test_rxt_03(self):

def test_rxt_04(self):
"""Verify lambda, m_r, m_t read correctly."""
exp = iadpython.read_rxt('./tests/data/sample-A.rxt')
filename = os.path.join(data_dir, 'sample-A.rxt')
exp = iadpython.read_rxt(filename)
self.assertAlmostEqual(exp.lambda0[0], 800)
self.assertAlmostEqual(exp.m_r[0], 0.16830, delta=1e-5)
self.assertAlmostEqual(exp.m_t[0], 0.24974, delta=1e-5)
Expand All @@ -53,7 +64,8 @@ def test_rxt_04(self):

def test_rxt_05(self):
"""Verify lambda, m_r read correctly."""
exp = iadpython.read_rxt('./tests/data/sample-B.rxt')
filename = os.path.join(data_dir, 'sample-B.rxt')
exp = iadpython.read_rxt(filename)
self.assertAlmostEqual(exp.lambda0[0], 800)
self.assertAlmostEqual(exp.m_r[0], 0.16830, delta=1e-5)
self.assertAlmostEqual(exp.lambda0[-1], 1000)
Expand Down
42 changes: 22 additions & 20 deletions tests/test_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
module_path = iadpython.__file__
print("Module imported from:", module_path)


class SimpleSphere(unittest.TestCase):
"""Creation and setting of sphere parameters."""

Expand Down Expand Up @@ -64,8 +65,8 @@ def test_02_gain(self):
s = iadpython.Sphere(d_sphere, d_sample, r_wall=1)
g = s.gain(sample_uru=0)
p = iadpython.Port(s, d_sample)
Asphere = 4 * np.pi * (d_sphere/2)**2
gg = Asphere/p.cap_area()
Asphere = 4 * np.pi * (d_sphere / 2)**2
gg = Asphere / p.cap_area()
np.testing.assert_allclose(g, gg, atol=1e-4)

def test_03_gain(self):
Expand All @@ -82,7 +83,7 @@ def test_04_gain(self):
d_sample = 25
s = iadpython.Sphere(d_sphere, d_sample, d_third=5, d_detector=10, r_wall=1)
g = s.gain(sample_uru=0)
gg = 1/(s.detector.a + s.third.a + s.sample.a)
gg = 1 / (s.detector.a + s.third.a + s.sample.a)
np.testing.assert_allclose(g, gg, atol=1e-5)

def test_05_gain(self):
Expand All @@ -96,66 +97,66 @@ def test_05_gain(self):

# class SphereMultiplierSamplePortOnly(unittest.TestCase):
# """Relative increase in radiative flux on sphere walls."""
#
#
# def setUp(self):
# """Set up test conditions for SphereMultiplier tests."""
# R = 100
# d_sphere = 2 * R
# d_sample = 20
# self.sphere = iadpython.Sphere(d_sphere, d_sample, r_wall=0)
#
#
# def test_01_multiplier(self):
# """Scalar calculations no reflection from sample, black walls."""
# M = self.sphere.multiplier(UX1=1, URU=0)
# np.testing.assert_allclose(self.sphere.a_wall, M, atol=1e-5)
#
#
# def test_02_multiplier(self):
# """Scalar calculation 80% transmission."""
# M = self.sphere.multiplier(UX1=0.8, URU=0)
# np.testing.assert_allclose(0.8 * self.sphere.a_wall, M, atol=1e-5)
#
#
# def test_03_multiplier(self):
# """Scalar calculations total transmission with total sample reflection"""
# M = self.sphere.multiplier(UX1=1, URU=1)
# M1 = self.sphere.a_wall / (1 - self.sphere.a_wall * self.sphere.r_wall - self.sphere.sample.a)
# np.testing.assert_allclose(M, M1, atol=1e-5)
#
#
# def test_04_multiplier(self):
# """Array of r_wall values."""
# self.sphere.r_wall = np.linspace(0, 1, 4)
# M = self.sphere.multiplier(UX1=1, URU=0)
# mm = self.sphere.a_wall / (1 - self.sphere.a_wall * self.sphere.r_wall)
# np.testing.assert_allclose(mm, M, atol=1e-5)
#
#
# def test_05_multiplier(self):
# """Array of r_wall values."""
# self.sphere.r_wall = np.linspace(0, 1, 4)
# M = self.sphere.multiplier(UX1=0.8, URU=0)
# mm = 0.8 * self.sphere.a_wall / (1 - self.sphere.a_wall * self.sphere.r_wall)
# np.testing.assert_allclose(mm, M, atol=1e-5)
#
#
# def test_06_multiplier(self):
# """Array of r_wall values."""
# self.sphere.r_wall = np.linspace(0, 1, 4)
# M = self.sphere.multiplier(UX1=1, URU=1)
# M1 = self.sphere.a_wall / (1 - self.sphere.a_wall * self.sphere.r_wall - self.sphere.sample.a)
# M1[3] = np.inf
# np.testing.assert_allclose(M, M1, atol=1e-5)
#
#
# class SphereMultiplier(unittest.TestCase):
# """Relative increase in radiative flux on sphere walls."""
#
#
# def setUp(self):
# """Set up test conditions for SphereMultiplier tests."""
# R = 100
# d_sphere = 2 * R
# d_sample = 20
# d_third = 20
# d_detector = 10
# self.sphere = iadpython.Sphere(d_sphere, d_sample,
# d_third=d_third, d_detector=d_detector,
# self.sphere = iadpython.Sphere(d_sphere, d_sample,
# d_third=d_third, d_detector=d_detector,
# r_detector=0.5, r_wall=0.95, refl=True)
#
#
# def test_01_multiplier(self):
# """Scalar calculations no reflection from sample, black walls."""
# URU = 0
Expand All @@ -167,7 +168,7 @@ def test_05_gain(self):
# denom -= self.sphere.detector.a * self.sphere.detector.uru
# M1 = UX1 * self.sphere.a_wall / denom
# np.testing.assert_allclose(M1, M, atol=1e-5)
#
#
# def test_02_multiplier(self):
# """Scalar calculation 80% transmission."""
# URU = 0
Expand All @@ -179,7 +180,7 @@ def test_05_gain(self):
# denom -= self.sphere.detector.a * self.sphere.detector.uru
# M1 = UX1 * self.sphere.a_wall / denom
# np.testing.assert_allclose(M1, M, atol=1e-5)
#
#
# def test_03_multiplier(self):
# """Scalar calculations total transmission with total sample reflection"""
# URU = 1
Expand All @@ -191,7 +192,7 @@ def test_05_gain(self):
# denom -= self.sphere.detector.a * self.sphere.detector.uru
# M1 = UX1 * self.sphere.a_wall / denom
# np.testing.assert_allclose(M1, M, atol=1e-5)
#
#
# def test_04_multiplier(self):
# """Array of r_wall values."""
# self.sphere.r_wall = np.linspace(0, 1, 4)
Expand All @@ -204,7 +205,7 @@ def test_05_gain(self):
# denom -= self.sphere.detector.a * self.sphere.detector.uru
# M1 = UX1 * self.sphere.a_wall / denom
# np.testing.assert_allclose(M1, M, atol=1e-5)
#
#
# def test_05_multiplier(self):
# """Array of r_wall values."""
# self.sphere.r_wall = np.linspace(0, 1, 4)
Expand All @@ -217,7 +218,7 @@ def test_05_gain(self):
# denom -= self.sphere.detector.a * self.sphere.detector.uru
# M1 = UX1 * self.sphere.a_wall / denom
# np.testing.assert_allclose(M1, M, atol=1e-5)
#
#
# def test_06_multiplier(self):
# """Array of r_wall values."""
# self.sphere.r_wall = np.linspace(0, 1, 4)
Expand All @@ -231,5 +232,6 @@ def test_05_gain(self):
# M1 = UX1 * self.sphere.a_wall / denom
# np.testing.assert_allclose(M1, M, atol=1e-5)


if __name__ == '__main__':
unittest.main()

0 comments on commit 5192fad

Please sign in to comment.