diff --git a/combidata/classes/data_generator.py b/combidata/classes/data_generator.py index 6c9b87c..ddf023b 100644 --- a/combidata/classes/data_generator.py +++ b/combidata/classes/data_generator.py @@ -10,11 +10,35 @@ def check_all_names(init_lib): name_set = set() - for cases in init_lib["cases"].values(): - for case in cases.values(): - assert case["name"] not in name_set, case["name"] + " - is not unique" + not_unic_items = "" + for field_name, cases in init_lib["cases"].items(): + for case_code, case in cases.items(): + if case["name"] in name_set: + not_unic_items += f"Case [{case_code}] for [{field_name}] have not unique name: {case['name']}\n" name_set.add(case["name"]) + if not_unic_items: + raise ValueError(not_unic_items) + + +def check_input_data(amount, banned_fields, possible_fields, library, logger, generator_id): + if not (amount is None or (isinstance(amount, int) and amount > 0)): + raise ValueError("Amount must be an integer greater than 0") + + if not (banned_fields is None or isinstance(banned_fields, list)): + raise TypeError("Banned_fields must be a list instance") + + if not (possible_fields is None or isinstance(possible_fields, list)): + raise TypeError("Possible_fields must be a list instance") + + if banned_fields is not None and possible_fields is not None: + raise ValueError("You can't use banned_fields and possible_fields arguments simultaneously") + + if not ((logger and generator_id) or logger is None): + raise ValueError("You must use both logger and generator_id, or neither") + + check_all_names(library) + class DataGenerator: """ @@ -55,11 +79,8 @@ def __init__(self, library: dict, generator_id: str = None): self.combinations = None - assert amount is None or (isinstance(amount, int) and amount > 0), "amount must be integer > 0" - assert banned_fields is None or isinstance(banned_fields, list), "banned_fields must be list instance" - assert possible_fields is None or isinstance(possible_fields, list), "possible_fields must be list instance" - assert banned_fields is None or possible_fields is None, "You can't use banned_fields and possible_fields arguments simultaneously" - check_all_names(library) + + check_input_data(amount, banned_fields, possible_fields, library, logger, generator_id) self.modes_for_gen = self.form_modes_for_gen(possible_modes) self.init_lib = self.form_init_lib(library) @@ -69,8 +90,6 @@ def __init__(self, library: dict, self.logger = logger self.generator_id = generator_id - assert (logger and generator_id) or logger is None, "You must use logger and generator_id" - self.type_of_cases = type_of_cases if type_of_cases else "standard" self.workflow = self.get_workflow(library["workflow"], type_of_cases) @@ -112,7 +131,7 @@ def run(self): for combination_name in combinations_names: self.combinations[combination_name].run() if isinstance(self.combinations[combination_name].step_done, type(CombinatoricsError())): - del self.combinations[combination_name] #todo logs! + del self.combinations[combination_name] # todo logs! def run_one(self): combinations = list(self.combinations.keys()) @@ -124,7 +143,7 @@ def run_one(self): def get_one(self): for test_case in unlimited_cases(self.init_lib, self.combinations, self.workflow, self.types_for_generation): - return test_case[list(test_case.keys())[0]] #todo ugly + return test_case[list(test_case.keys())[0]] # todo ugly # todo def any_passed @staticmethod @@ -165,4 +184,3 @@ def dell_fields(self, possible_fields, banned_fields): field not in possible_fields] for field in banned_fields: del self.init_lib[field] - diff --git a/combidata/funcs/form_and_combine.py b/combidata/funcs/form_and_combine.py index ddda492..0bfbe97 100644 --- a/combidata/funcs/form_and_combine.py +++ b/combidata/funcs/form_and_combine.py @@ -54,7 +54,9 @@ def can_combine(neutral_lib, current_case, types_for_generation): fields = [list(mode.values()) for mode in copied_lib.values()] random.shuffle(fields) fields = list(filter(should_keep, fields)) - for case in fields[0]: + cases = fields[0] + random.shuffle(cases) + for case in cases: if case.type_of_case in types_for_generation and (result := can_combine(copied_lib, case, types_for_generation)): return result else: diff --git a/combidata/processes/form.py b/combidata/processes/form.py index c46cc07..a2fda38 100644 --- a/combidata/processes/form.py +++ b/combidata/processes/form.py @@ -14,4 +14,8 @@ def find_replace_in_dict(template, generated_data, keys): def form(combination): combination.formed_data = find_replace_in_dict(combination.template, combination.generated_data, combination.init_lib.keys()) + if combination.logger: + combination.logger.add_log(combination.generator_id, + f"Formed data: {str(combination.formed_data)}") + return True \ No newline at end of file diff --git a/combidata/processes/genetate.py b/combidata/processes/genetate.py index 6623819..647edaa 100644 --- a/combidata/processes/genetate.py +++ b/combidata/processes/genetate.py @@ -45,4 +45,8 @@ def generate(combination: Combination): case = random.choice(all_fields) generate_value(all_fields, case, combination) + if combination.logger: + combination.logger.add_log(combination.generated_data, + f"Generated data: {str(combination.test_seed)}") + return True \ No newline at end of file diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 5d4e826..dbf0452 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -3,6 +3,14 @@ hide: - navigation --- +# Release Notes: Version 0.2.8 + +## Enhancements: +1. **Enhanced Exception Clarity:** Error messages are now more understandable, and appropriate exceptions are raised. This improvement helps you identify launch issues and alerts you to any non-unique names. +2. **Logging in Standard Steps:** All standard steps now feature logging, providing better insight and traceability during testing. + +## Bug Fixes: +1. **Randomized Case Selection:** Combidata now randomly combines cases, enhancing the diversity and effectiveness of testing scenarios. # Release Notes: Version 0.2.7 diff --git a/pyproject.toml b/pyproject.toml index 2a4fb7b..b7d2c1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,4 +17,4 @@ keywords = [ urls = {Homepage = "https://github.com/Warrfie/combidata"} authors = [{name = "MaximKuklikov(Warrfie)", email = "warrfie@gmail.com"}] requires-python = ">=3.10" -version="0.2.7" +version="0.2.8" diff --git a/setup.py b/setup.py index b36a106..19fb2d2 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="combidata", - version="0.2.7", + version="0.2.8", description="Package for random data generation and combination different cases", long_description=open('README.md').read(), url="https://warrfie.github.io/combidata",