Skip to content

Commit

Permalink
Update some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Dec 20, 2024
1 parent d9d23c1 commit 7577969
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
38 changes: 23 additions & 15 deletions src/pyFAI/test/test_integrate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
__contact__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "15/04/2024"
__date__ = "20/12/2024"

import os
import json
Expand All @@ -50,31 +50,31 @@ def test_poni(self):
config = {"poni": utilstest.UtilsTest.getimage("Pilatus1M.poni"),
"wavelength": 50}
config = integration_config.normalize(config)
self.assertNotIn("poni", config)
# self.assertNotIn("poni", config)
# From PONI file
self.assertEqual(config["dist"], 1.58323111834)
self.assertEqual(config["poni"]["dist"], 1.58323111834)
# From dict
self.assertEqual(config["wavelength"], 50)
self.assertEqual(config["poni"]["wavelength"], 50)

def test_single_flatdark(self):
config = {"dark_current": "abc",
"flat_field": "abd"}
config = integration_config.normalize(config)
self.assertEqual(config["dark_current"], "abc")
self.assertEqual(config["flat_field"], "abd")
self.assertEqual(config["dark_current_image"], "abc")
self.assertEqual(config["flat_field_image"], "abd")

def test_coma_flatdark(self):
config = {"dark_current": "a,b,c",
"flat_field": "a,b,d"}
config = integration_config.normalize(config)
self.assertEqual(config["dark_current"], ["a", "b", "c"])
self.assertEqual(config["flat_field"], ["a", "b", "d"])
self.assertEqual(config["dark_current_image"], ["a", "b", "c"])
self.assertEqual(config["flat_field_image"], ["a", "b", "d"])

def test_pilatus(self):
config = {"detector": "pilatus2m"}
config = integration_config.normalize(config)
self.assertEqual(config["detector"], "Pilatus2M")
self.assertIsInstance(config["detector_config"], dict)
self.assertEqual(config["poni"]["detector"], "Pilatus2M")
self.assertIsInstance(config["poni"]["detector_config"], dict)

def test_detector(self):
config = {"detector": "detector",
Expand All @@ -83,18 +83,18 @@ def test_detector(self):
config = integration_config.normalize(config)
self.assertNotIn("pixel1", config)
self.assertNotIn("pixel2", config)
self.assertEqual(config["detector"], "Detector")
self.assertEqual(config["detector_config"]["pixel1"], 1.0)
self.assertEqual(config["detector_config"]["pixel2"], 1.0)
self.assertEqual(config["poni"]["detector"], "Detector")
self.assertEqual(config["poni"]["detector_config"]["pixel1"], 1.0)
self.assertEqual(config["poni"]["detector_config"]["pixel2"], 1.0)

def test_frelon(self):
spline_file = utilstest.UtilsTest.getimage("frelon.spline")
config = {"detector": "frelon",
"splineFile": spline_file}
config = integration_config.normalize(config)
self.assertNotIn("splineFile", config)
self.assertEqual(config["detector"], "FReLoN")
self.assertEqual(config["detector_config"]["splineFile"], spline_file)
self.assertEqual(config["poni"]["detector"], "FReLoN")
self.assertEqual(config["poni"]["detector_config"]["splineFile"], spline_file)

def test_opencl(self):
config = {"do_OpenCL": True}
Expand Down Expand Up @@ -151,6 +151,14 @@ def test_2132(self):
expected = expected_with_gpu if ocl else expected_without_gpu
self.assertEqual(parsed_config["ai"]["method"], expected, "method match with -g option")

def test_dataclass(self):
test_files = "0.14_verson0.json id11_v0.json id13_v0.json id15_1_v0.json id15_v0.json id16_v3.json id21_v0.json version0.json version3.json version4.json"
for fn in test_files.split():
js = utilstest.UtilsTest.getimage(fn)
with utilstest.TestLogging(logger='pyFAI.io.integrarion_config', warning=0):
# with self.assertLogs('pyFAI.io.integrarion_config', level='WARNING') as cm:
wc = integration_config.WorkerConfig.load(js)
self.assertEqual(wc, integration_config.WorkerConfig.from_dict(wc.as_dict()), f"Idempotent {fn}")


def suite():
Expand Down
12 changes: 0 additions & 12 deletions src/pyFAI/test/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,18 +557,6 @@ def test_v3_equal_to_v4(self):
poni_v4_from_config = PoniFile(data=config_v4)
self.assertEqual(poni_v3_from_config.as_dict(), poni_v4_from_config.as_dict(), "PONI dictionaries from config match")

def test_dataclass(self):
test_files = "0.14_verson0.json id11_v0.json id13_v0.json id15_1_v0.json id15_v0.json id16_v3.json id21_v0.json version0.json version3.json version4.json"
for fn in test_files.split():
js = utilstest.UtilsTest.getimage(fn)
with utilstest.TestLogging(logger='pyFAI.io.integrarion_config', warning=0):
# with self.assertLogs('pyFAI.io.integrarion_config', level='WARNING') as cm:
wc = WorkerConfig.load(js)
self.assertEqual(wc, WorkerConfig.from_dict(wc.as_dict()), f"Idempotent {fn}")





def suite():
loader = unittest.defaultTestLoader.loadTestsFromTestCase
Expand Down

0 comments on commit 7577969

Please sign in to comment.