Skip to main content

Package for random data generation, combination and data prepare for tests

Project description

PyPi Package Version Supported Python versions PyPi status

Combidata

Combidata is a flexible and powerful Python library designed for generating various combinations of test data based on defined cases and rules. It is especially useful for testing, debugging, and analyzing software applications and systems.

The core functionality of the Combidata library is provided by the DataGenerator class, which takes in test flags and a dictionary containing all cases, forms, and workflows. The DataGenerator creates Combination instances from the possible cases. The run function in each Combination instance processes all steps in the specified workflow.

New features

0.2.2:

  1. All combination problems was fixed by multidimensional graph (I will optimize algorithm in next realises)
  2. Added logger

0.2.1:

  1. So, we have greate problem with possible_modes and other parameters. I patched it but problem still here.
  2. Added logger begin
  3. And also fix bug with 'STOP' signal

0.2.0:

  1. Ok, now its Beta ;)
  2. Fixed combination bug

0.1.9:

  1. Now you can use 'types_for_generation' in initialisation of 'DataGenerator'

0.1.8:

  1. Now you can use multiply symbols modes
  2. Generate any number of data combinations, even if there are only a few cases.
  3. Use the get_one() function in the DataGenerator class for generating a single Combination object.

Structure of input library

library = {
            "cases": {},
            "workflow": (ST_COMBINE, ST_GENERATE, ST_FORM),
            "tools": {},
            "template": {}
}

The cases key contains a library instance with all your defined cases.

The workflow key stores a list of tuple or one tuple of processes to be executed. If you use list, every run() function will process all steps in the current tuple

The tools key holds a dictionary with items that can be utilized within the processes.

Finally, the template key contains a template used for exporting the results.

Cases

Cases structure hold fields names as keys and every field name holds field cases codes as a keys and every field cases codes holds case structure. I know, very complicate, but example will help you:

library["cases"]["NAME"] = {
        "True": {
            "gen_func": re_generate,
            "value": r"[a-zA-Z]{50}",
            "name": "Standart NAME check"
        },
        "False": {
            "value": "12345",
            "type": "error",
            "name": "Check NAME with error"
        },
        "None": {
            "value": None,
            "requirements": {"CODE": "T"},
            "is_presented": False,
            "name": "Check NAME for not necessary field"
        }}
library["cases"]["CODE"] = {
        "T": {
            "gen_func": code_generator,
            "value": "token",
            "options": {"combination": "combination", "example_token": "wa69sf"},
            "name": "Standart CODE check"
        },
        "N": {
            "value": None,
            "is_presented": False,
            "name": "Check CODE for not necessary field"
        }
}

Let's know about keys in case structure: "name" - (string) necessary value and must be uniq. If that case is major - all combination unit will hand it "gen_func" - (function) holds function for generation by default takes only one argument "value" - (anything) holds case value it will be first argument of gen_func if gen_func in case "options" - (dictionary) holds functions nd another stuff which will unpack into gen_func. "combination" is reserved string "is_presented" - (boolean) holds flag for export function. It will be not exported if False. "requirements" - (dictionary) holds possible modes of another fields "type" - (string) Generator will choose that case like main case when you will run test of that type

Workflow

Holds tuple of processes or list of processes. When you will run combination or generator it will run all processes in tuple Also yoy can use dict for hold workflow for tests with different types. "standard" is reserved key for standard workflow

"workflow": (ST_COMBINE, ST_GENERATE, ST_FORM)
or 
"workflow": [(ST_COMBINE, ST_GENERATE, ST_FORM), (ANOTHER_STEP)]
or 
"workflow": {
    "standard": (ST_COMBINE, ST_GENERATE, ST_FORM),
    "error": [(ST_COMBINE, ST_GENERATE, ST_FORM), (ANOTHER_STEP)]
}

don't forget use another run if you use list workflow

about processes, feed Process instance with process name and process function

ST_COMBINE = Process("ST_COMBINE", combine)

Process must return True when it over or Generator will run it infinitely you can stop all workflow just put in combination.step_done reserved string "STOP"

combination.step_done = "STOP"

Tools

Just warehouse for items, funcs or other stuff that you can use in steps or generators via .tools

"tools": {
    "UTILS": utilites,
    "TOKEN": token_generator
}

#....

block = combination.tools["UTILS"].get_block()

Template

Holds template of generation result. All case codes will be reserved and will be replaced in template like that

"template": {
    "NAME": "NAME",
    "code": "CODE"
}

Result will look like

{"NAME": "azRkdSS", "code": "12GG233"}

Example

import pytest

from combidata import ST_COMBINE, ST_GENERATE, ST_FORM, DataGenerator
import re_generate

re_generate = re_generate.get_str
def code_generator(value, combination, example_token):
    # just for test
    return "12GG233"

library = {
    "cases": {},
    "workflow": (ST_COMBINE, ST_GENERATE, ST_FORM),
    "tools": {},
    "template": {
        "NAME": "NAME",
        "code": "CODE"
    }
}
library["cases"]["NAME"] = {
    "T": {
        "gen_func": re_generate,
        "value": r"[a-zA-Z]{50}",
        "name": "Standart NAME check"
    },
    "F": {
        "value": "12345",
        "type": "error",
        "name": "Check NAME with error"
    },
    "N": {
        "value": None,
        "requirements": {"CODE": "T"},
        "is_presented": False,
        "name": "Check NAME for not necessary field"
    }}
library["cases"]["CODE"] = {
    "T": {
        "gen_func": code_generator,
        "value": "token",
        "options": {"combination": "combination", "example_token": "wa69sf"},
        "name": "Standart CODE check"
    },
    "N": {
        "value": None,
        "is_presented": False,
        "name": "Check CODE for not necessary field"
    }
}

generator = DataGenerator(library)
generator.run()
@pytest.mark.parametrize("combination_name", generator.combinations.keys())
def test(combination_name):
    combination = generator.combinations[combination_name]
    print()
    assert combination.test_seed != {'CODE': 'N', 'NAME': 'N'}
    print(combination.test_seed)
    print()
    print(combination.generated_data)

It will print in console

PASSED                      [ 25%]
{'NAME': 'T', 'CODE': 'T'}

{'NAME': 'OexmkFKlAyJkNqNHLnoGkcCgNmGkCVkAfHvOWeNfwEFeyhCjAt', 'CODE': '12GG233'}
PASSED       [ 50%]
{'NAME': 'N', 'CODE': 'T'}

{'CODE': '12GG233'}
PASSED                      [ 75%]
{'CODE': 'T', 'NAME': 'N'}

{'CODE': '12GG233'}
PASSED       [100%]
{'CODE': 'N', 'NAME': 'T'}

{'NAME': 'BlvUbOLHjWlqXkSHqkeGumnnhIbrPvuhkxhddTrMVAwaolyCwY'}

And never failed because I made requirements to "NAME" - "N" field

I added it in project "tests" directory

Installation

This package is tested with Python 3.9-3.11 and Pypy 3. There are two ways to install the library:

  • Installation using pip (a Python package manager):
pip install combidata
  • Installation from source (requires git):
git clone https://github.com/Warrfie/combidata
cd combidata
python setup.py install

or:

pip install git+https://github.com/Warrfie/combidata

It is generally recommended to use the first option.

Package is still under development, and it has regular updates, do not forget to update it regularly by calling

pip install combidata --upgrade

Contributing

Contributions are welcome! Please feel free to submit pull requests, report bugs, or suggest new features through the GitHub repository. We appreciate your help in improving Combidata!

License

Combidata is released under the MIT License. See the LICENSE file for more details.

Support

If you need help with Combidata or have any questions, please open an issue on GitHub or contact the maintainers directly

Telegram — https://t.me/sasisochka

Linkedin — https://www.linkedin.com/in/yasasisochka/

Acknowledgments

A special thanks to the community for their support, contributions, and valuable feedback. Your input helps make Combidata a better tool for everyone! And a special thanks to JetBrains for their best software and License for Open Source Development.

JetBrains Black Box Logo logo

With Combidata, you can easily generate test data for your applications and systems, ensuring that they are robust and reliable under various conditions. Start using Combidata today to improve the quality of your testing and development process!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

combidata-0.2.2.4.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

combidata-0.2.2.4-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file combidata-0.2.2.4.tar.gz.

File metadata

  • Download URL: combidata-0.2.2.4.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for combidata-0.2.2.4.tar.gz
Algorithm Hash digest
SHA256 3f941ad12939f310c5b007c14b17451dbdac30cafc2bc64e65602c2c6d44e8e1
MD5 e3e2b3b01ee5364019327a7ed8d2f335
BLAKE2b-256 1a10ce04f60e4003186f43dac1f2d9d77c6962c65de80b91708e8898777c0d4d

See more details on using hashes here.

File details

Details for the file combidata-0.2.2.4-py3-none-any.whl.

File metadata

  • Download URL: combidata-0.2.2.4-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for combidata-0.2.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 421ec7743ffbbad3f63974fa6a346f55ba6f0bee185ce8c54767985ac6950208
MD5 f8d5e78048320d74ed30f9a59f96d740
BLAKE2b-256 35144c09ea7a15e91bac4a28a19127e0c40f874a6326303b855af006657d8572

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page