MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / test_ParamQuantitativeAnalysis

Function test_ParamQuantitativeAnalysis

pyxrf/core/tests/test_quant_analysis.py:815–1124  ·  view source on GitHub ↗
(tmp_path)

Source from the content-addressed store, hash-verified

813
814
815def test_ParamQuantitativeAnalysis(tmp_path):
816 incident_energy = 12.0
817 file_paths, img_list = create_ref_calib_data(tmp_path, incident_energy=incident_energy)
818
819 n_entries = len(file_paths)
820 assert n_entries >= 2, "The number of calibration data entries must be >= 2. Test can not be performed."
821 fln0 = file_paths[0]
822
823 # Load all QA calibration files
824 pqa = ParamQuantitativeAnalysis()
825 for fpath in file_paths:
826 pqa.load_entry(file_path=fpath) # Use kwarg
827
828 # Check if the number of calibration entries is equal to the number of loaded files
829 # Also check if the function 'get_n_entries' works
830 assert pqa.get_n_entries() == n_entries, "Incorrect number of loaded calibration data entries"
831
832 # Check 'get_file_path_list' function
833 assert (
834 pqa.get_file_path_list() == file_paths
835 ), "The returned list of file paths is not the same as the expected list"
836
837 # Attempt to load calibration file that was already loaded
838 # Should not be loaded, the number of entries should remain unchanged
839 pqa.load_entry(fln0) # Send 'fpath' as arg, not kwarg
840 assert len(pqa.calibration_data) == n_entries, "Incorrect number of loaded calibration data entries"
841 assert len(pqa.calibration_settings) == n_entries, "Unexpected number of 'calibration_settings' elements"
842
843 # Try removing the calibration data entry (the first)
844 pqa.remove_entry(file_path=fln0)
845 assert len(pqa.calibration_data) == n_entries - 1, "The result of calibration entry removal is not as expected"
846 assert len(pqa.calibration_settings) == n_entries - 1, "Unexpected number of 'calibration_settings' elements"
847
848 # Reload the deleted calibration data entry
849 pqa.load_entry(fln0) # Send 'fpath' as arg, not kwarg
850 assert len(pqa.calibration_data) == n_entries, "Incorrect number of loaded calibration data entries"
851 assert len(pqa.calibration_settings) == n_entries, "Unexpected number of 'calibration_settings' elements"
852 # Make sure that the last element contains the last loaded calibration data entry
853 assert (
854 pqa.calibration_settings[-1]["file_path"] == fln0
855 ), "The last element of 'calibration_settings' list contains wrong calibration data entry"
856
857 # Find the index of calibration data entry (by file name)
858 for n, fp in enumerate(file_paths):
859 n_expected = n - 1
860 if n_expected < 0:
861 n_expected += n_entries # n_entries - the number of configuration entries (files)
862 assert (
863 pqa.find_entry_index(fp) == n_expected
864 ), f"Index of the calibration entry '{fp}' is determined incorrectly"
865
866 # Test preview function
867 for fp in file_paths:
868 assert pqa.get_entry_text_preview(fp), f"Failed to generate text preview for the calibration entry '{fp}'"
869
870 # Get the emission line list and verify if it matches the expected list (including the order of the lines)
871 eline_list_expected = []
872 for settings in pqa.calibration_settings:

Callers

nothing calls this directly

Calls 15

load_entryMethod · 0.95
get_n_entriesMethod · 0.95
get_file_path_listMethod · 0.95
remove_entryMethod · 0.95
find_entry_indexMethod · 0.95
is_eline_selectedMethod · 0.95
select_elineMethod · 0.95
get_eline_calibrationMethod · 0.95

Tested by

no test coverage detected