Ejemplo n.º 1
0
 def load_part(cls, file_path):
     data = cls.load_metadata(file_path)
     bad_key = []
     if isinstance(data, MutableMapping) and not check_loaded_dict(data):
         for k, v in data.items():
             if not check_loaded_dict(v):
                 bad_key.append(k)
         for el in bad_key:
             del data[el]
     elif isinstance(data, ProfileDict) and not data.verify_data():
         bad_key = data.filter_data()
     return data, bad_key
Ejemplo n.º 2
0
    def test_profile_execute(self, data_test_dir):
        profile_path = os.path.join(data_test_dir, "segment_profile_test.json")
        # noinspection PyBroadException
        try:
            data = UpdateLoadedMetadataAnalysis.load_json_data(profile_path)
            assert check_loaded_dict(data)
        except Exception:  # pylint: disable=W0703
            pytest.fail("Fail in loading profile")
            return
        image = TiffImageReader.read_image(
            os.path.join(data_test_dir, "stack1_components",
                         "stack1_component5.tif"),
            os.path.join(data_test_dir, "stack1_components",
                         "stack1_component5_mask.tif"),
        )

        val: ROIExtractionProfile
        for val in data.values():
            algorithm: ROIExtractionAlgorithm = analysis_algorithm_dict[
                val.algorithm]()
            algorithm.set_image(image)
            algorithm.set_mask(image.mask.squeeze())
            algorithm.set_parameters(**val.values)
            result = algorithm.calculation_run(empty)
            assert np.max(result.roi) == 2
Ejemplo n.º 3
0
 def test_profile_load(self, data_test_dir):
     profile_path = os.path.join(data_test_dir, "segment_profile_test.json")
     # noinspection PyBroadException
     try:
         with open(profile_path, "r") as ff:
             data = json.load(ff, object_hook=part_hook)
         assert check_loaded_dict(data)
     except Exception:
         pytest.fail("Fail in loading profile")
Ejemplo n.º 4
0
 def test_measure_load(self, data_test_dir):
     profile_path = os.path.join(data_test_dir, "measurements_profile_test.json")
     # noinspection PyBroadException
     try:
         with open(profile_path) as ff:
             data = json.load(ff, object_hook=part_hook)
         assert check_loaded_dict(data)
     except Exception:  # pylint: disable=W0703
         pytest.fail("Fail in loading profile")
Ejemplo n.º 5
0
    def test_json_load(self):
        class Test(Enum):
            test0 = 0
            test1 = 1
            test2 = 2

        test_json = json.dumps(Test.test0, cls=PartEncoder)

        assert not check_loaded_dict(json.loads(test_json, object_hook=part_hook))

        enum_register.register_class(Test)
        assert isinstance(json.loads(test_json, object_hook=part_hook), Test)