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

Function test_ParamQuantEstimation_2

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

Source from the content-addressed store, hash-verified

568
569
570def test_ParamQuantEstimation_2(tmp_path):
571 standard_data = _standard_data_sample
572
573 # 'home_dir' is typically '~', but for testing it is set to 'tmp_dir'
574 home_dir = tmp_path
575 config_dir = ".pyxrf"
576 standards_fln = "quantitative_standards.yaml"
577
578 # Create the file with user-defined reference definitions
579 file_path = os.path.join(home_dir, config_dir, standards_fln)
580 save_xrf_standard_yaml_file(file_path, standard_data)
581
582 # Create the object and load references
583 pqe = ParamQuantEstimation(home_dir=home_dir)
584 pqe.load_standards()
585 assert pqe.standards_built_in is not None, "Failed to load built-in standards"
586 assert len(pqe.standards_built_in) > 0, "The number of loaded built-in standards is ZERO"
587 assert pqe.standards_custom is not None, "Failed to load user-defined standards"
588 assert len(pqe.standards_custom) > 0, "The number of loaded user-defined standards is ZERO"
589
590 # Verify if the functions for searching the user-defined standards
591 for st in pqe.standards_custom:
592 serial = st["serial"]
593 assert pqe._find_standard_custom(st), f"Standard {serial} was not found in user-defined list"
594 assert not pqe._find_standard_built_in(st), f"Standard {serial} was found in built-in list"
595 assert pqe.find_standard(st), f"Standard {serial} was not found"
596 assert pqe.find_standard(st["name"], key="name"), f"Failed to find standard {serial} by name"
597 assert pqe.find_standard(st["serial"], key="serial"), f"Failed to find standard {serial} by serial number"
598 assert pqe.is_standard_custom(st), f"Standard {serial} was not identified as user-defined"
599 pqe.set_selected_standard(st)
600 assert pqe.standard_selected == st, f"Can't select standard {serial}"
601
602 # Verify if the functions for searching the user-defined standards
603 for st in pqe.standards_built_in:
604 serial = st["serial"]
605 assert not pqe._find_standard_custom(st), f"Standard {serial} was found in user-defined list"
606 assert pqe._find_standard_built_in(st), f"Standard {serial} was not found in built-in list"
607 assert pqe.find_standard(st), f"Standard {serial} was not found"
608 assert pqe.find_standard(st["name"], key="name"), f"Failed to find standard {serial} by name"
609 assert pqe.find_standard(st["serial"], key="serial"), f"Failed to find standard {serial} by serial number"
610 assert not pqe.is_standard_custom(st), f"Standard {serial} was identified as user-defined"
611 pqe.set_selected_standard(st)
612 assert pqe.standard_selected == st, f"Can't select standard {serial}"
613
614 # Selecting non-existing standard
615 st = {"serial": "09876", "name": "Some name"} # Some arbitatry dictionary
616 st_selected = pqe.set_selected_standard(st)
617 assert st_selected == pqe.standard_selected, "Return value of 'set_selected_standard' is incorrect"
618 assert st_selected == pqe.standards_custom[0], "Incorrect standard is selected"
619 # No argument (standard is None)
620 pqe.set_selected_standard()
621 assert st_selected == pqe.standards_custom[0], "Incorrect standard is selected"
622 # Delete the user-defined standards (this is not normal operation, but it's OK for testing)
623 pqe.standards_custom = None
624 pqe.set_selected_standard(st)
625 assert pqe.standard_selected == pqe.standards_built_in[0], "Incorrect standard is selected"
626 pqe.standards_built_in = None
627 pqe.set_selected_standard(st)

Callers

nothing calls this directly

Calls 8

load_standardsMethod · 0.95
_find_standard_customMethod · 0.95
find_standardMethod · 0.95
is_standard_customMethod · 0.95
set_selected_standardMethod · 0.95

Tested by

no test coverage detected