Skip to content

Commit

Permalink
"0.2.8" Clarity and Randomization Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Warrfie committed Dec 13, 2023
1 parent 594e4de commit 0ee61bd
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
44 changes: 31 additions & 13 deletions combidata/classes/data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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]

4 changes: 3 additions & 1 deletion combidata/funcs/form_and_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions combidata/processes/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions combidata/processes/genetate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ keywords = [
urls = {Homepage = "https://github.com/Warrfie/combidata"}
authors = [{name = "MaximKuklikov(Warrfie)", email = "[email protected]"}]
requires-python = ">=3.10"
version="0.2.7"
version="0.2.8"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0ee61bd

Please sign in to comment.