pax_global_header00006660000000000000000000000064144522234320014513gustar00rootroot0000000000000052 comment=fb5c9a486a9aab1fce504bb3b45d2f87de077e61 allpairspy-2.5.1/000077500000000000000000000000001445222343200137005ustar00rootroot00000000000000allpairspy-2.5.1/.github/000077500000000000000000000000001445222343200152405ustar00rootroot00000000000000allpairspy-2.5.1/.github/FUNDING.yml000066400000000000000000000012031445222343200170510ustar00rootroot00000000000000# These are supported funding model platforms github: thombashi patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] allpairspy-2.5.1/.github/workflows/000077500000000000000000000000001445222343200172755ustar00rootroot00000000000000allpairspy-2.5.1/.github/workflows/tests.yml000066400000000000000000000042261445222343200211660ustar00rootroot00000000000000name: Tests on: push: paths-ignore: - '.gitignore' - 'README.rst' pull_request: paths-ignore: - '.gitignore' - 'README.rst' jobs: build-package: runs-on: ubuntu-latest concurrency: group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-build cancel-in-progress: true timeout-minutes: 20 container: image: ghcr.io/thombashi/python-ci:3.11 steps: - uses: actions/checkout@v3 - run: make build lint: runs-on: ubuntu-latest concurrency: group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-lint cancel-in-progress: true timeout-minutes: 20 container: image: ghcr.io/thombashi/python-ci:3.11 steps: - uses: actions/checkout@v3 - run: make check unit-test: timeout-minutes: 20 runs-on: ${{ matrix.os }} concurrency: group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref_name }}-ut-${{ matrix.os }}-${{ matrix.python-version }} cancel-in-progress: true strategy: fail-fast: false matrix: python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.10'] os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v3 - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: pip cache-dependency-path: | setup.py **/*requirements.txt tox.ini - name: Install pip run: python -m pip install --upgrade --disable-pip-version-check "pip>=21.1" - run: make setup-ci - name: Run tests run: tox -e cov env: PYTEST_DISCORD_WEBHOOK: ${{ secrets.PYTEST_DISCORD_WEBHOOK }} - name: Upload coverage report if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8' run: | python -m pip install --upgrade --disable-pip-version-check coveralls tomli coveralls --service=github env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} allpairspy-2.5.1/.gitignore000066400000000000000000000025701445222343200156740ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv .python-version # celery beat schedule file celerybeat-schedule # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # User settings _sandbox/ *_profile Untitled.ipynb allpairspy-2.5.1/CHANGES.txt000066400000000000000000000016311445222343200155120ustar00rootroot00000000000000Since 2.1.0: https://github.com/thombashi/allpairspy/releases Version 2.0.1 (April 4, 2009): - Moved examples into their own directory. - 'example2.2.py' re-written to get rid of frivolous usage of decorators (thanks to Tennis Smith for bringing the example's apparent complexity to our attention). - Easier installation through distutils-based setup.py script. - Created AllPairs project on SourceForge.net with home page at http://apps.sourceforge.net/trac/allpairs/. - Submitted the project to the Python Package Index at http://pypi.python.org/pypi. Version 2.0 (December 2007): - Ability to produce n-wise combinations. - Released as open source to MetaCommunications Engineering website (http://engineering.meta-comm.com). Version 1.0 (May 2002): Initial version, widely adopted at MetaCommunications Inc. for multiple testing projects. allpairspy-2.5.1/LICENSE.txt000066400000000000000000000020611445222343200155220ustar00rootroot00000000000000Copyright (c) 2002-2009, MetaCommunications Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. allpairspy-2.5.1/MANIFEST.in000066400000000000000000000002701445222343200154350ustar00rootroot00000000000000include LICENSE.txt include README.rst include setup.cfg include tox.ini recursive-include requirements * recursive-include tests * global-exclude __pycache__/* global-exclude *.pyc allpairspy-2.5.1/Makefile000066400000000000000000000017711445222343200153460ustar00rootroot00000000000000OWNER := thombashi PACKAGE := allpairspy BUILD_WORK_DIR := _work DIST_DIR := $(BUILD_WORK_DIR)/$(PACKAGE)/dist PKG_BUILD_DIR := $(BUILD_WORK_DIR)/$(PACKAGE) PYTHON := python3 .PHONY: build build: clean @$(PYTHON) -m tox -e build ls -lh dist/* .PHONY: build-remote build-remote: clean @mkdir -p $(BUILD_WORK_DIR) @cd $(BUILD_WORK_DIR) && \ git clone --depth 1 https://github.com/$(OWNER)/$(PACKAGE).git && \ cd $(PACKAGE) && \ $(PYTHON) -m tox -e build ls -lh $(PKG_BUILD_DIR)/dist/* .PHONY: check check: @$(PYTHON) -m tox -e lint .PHONY: clean clean: @rm -rf $(BUILD_WORK_DIR) @$(PYTHON) -m tox -e clean .PHONY: fmt fmt: $(PYTHON) -m tox -e fmt .PHONY: release release: @cd $(PKG_BUILD_DIR) && @$(PYTHON) setup.py release --verbose @$(MAKE) clean .PHONY: setup-ci setup-ci: @$(PYTHON) -m pip install -q --disable-pip-version-check --upgrade tox .PHONY: setup setup: setup-ci @$(PYTHON) -m pip install -q --disable-pip-version-check --upgrade -e .[test] releasecmd @$(PYTHON) -m pip check allpairspy-2.5.1/README.rst000066400000000000000000000277321445222343200154020ustar00rootroot00000000000000.. contents:: **allpairspy** forked from `bayandin/allpairs `__ :backlinks: top :depth: 2 .. image:: https://badge.fury.io/py/allpairspy.svg :target: https://badge.fury.io/py/allpairspy :alt: PyPI package version .. image:: https://img.shields.io/pypi/pyversions/allpairspy.svg :target: https://pypi.org/project/allpairspy :alt: Supported Python versions .. image:: https://github.com/thombashi/allpairspy/workflows/Tests/badge.svg :target: https://github.com/thombashi/allpairspy/actions?query=workflow%3ATests :alt: Linux/macOS/Windows CI status .. image:: https://coveralls.io/repos/github/thombashi/allpairspy/badge.svg?branch=master :target: https://coveralls.io/github/thombashi/allpairspy?branch=master :alt: Test coverage AllPairs test combinations generator ------------------------------------------------ AllPairs is an open source test combinations generator written in Python, developed and maintained by MetaCommunications Engineering. The generator allows one to create a set of tests using "pairwise combinations" method, reducing a number of combinations of variables into a lesser set that covers most situations. For more info on pairwise testing see http://www.pairwise.org. Features -------- * Produces good enough dataset. * Pythonic, iterator-style enumeration interface. * Allows to filter out "invalid" combinations during search for the next combination. * Goes beyond pairs! If/when required can generate n-wise combinations. Get Started --------------- Basic Usage ================== :Sample Code: .. code:: python from allpairspy import AllPairs parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] print("PAIRWISE:") for i, pairs in enumerate(AllPairs(parameters)): print("{:2d}: {}".format(i, pairs)) :Output: .. code:: PAIRWISE: 0: ['Brand X', '98', 'Internal', 'Salaried', 6] 1: ['Brand Y', 'NT', 'Modem', 'Hourly', 6] 2: ['Brand Y', '2000', 'Internal', 'Part-Time', 10] 3: ['Brand X', 'XP', 'Modem', 'Contr.', 10] 4: ['Brand X', '2000', 'Modem', 'Part-Time', 15] 5: ['Brand Y', 'XP', 'Internal', 'Hourly', 15] 6: ['Brand Y', '98', 'Modem', 'Salaried', 30] 7: ['Brand X', 'NT', 'Internal', 'Contr.', 30] 8: ['Brand X', '98', 'Internal', 'Hourly', 60] 9: ['Brand Y', '2000', 'Modem', 'Contr.', 60] 10: ['Brand Y', 'NT', 'Modem', 'Salaried', 60] 11: ['Brand Y', 'XP', 'Modem', 'Part-Time', 60] 12: ['Brand Y', '2000', 'Modem', 'Hourly', 30] 13: ['Brand Y', '98', 'Modem', 'Contr.', 15] 14: ['Brand Y', 'XP', 'Modem', 'Salaried', 15] 15: ['Brand Y', 'NT', 'Modem', 'Part-Time', 15] 16: ['Brand Y', 'XP', 'Modem', 'Part-Time', 30] 17: ['Brand Y', '98', 'Modem', 'Part-Time', 6] 18: ['Brand Y', '2000', 'Modem', 'Salaried', 6] 19: ['Brand Y', '98', 'Modem', 'Salaried', 10] 20: ['Brand Y', 'XP', 'Modem', 'Contr.', 6] 21: ['Brand Y', 'NT', 'Modem', 'Hourly', 10] Filtering ================== You can restrict pairs by setting a filtering function to ``filter_func`` at ``AllPairs`` constructor. :Sample Code: .. code:: python from allpairspy import AllPairs def is_valid_combination(row): """ This is a filtering function. Filtering functions should return True if combination is valid and False otherwise. Test row that is passed here can be incomplete. To prevent search for unnecessary items filtering function is executed with found subset of data to validate it. """ n = len(row) if n > 1: # Brand Y does not support Windows 98 if "98" == row[1] and "Brand Y" == row[0]: return False # Brand X does not work with XP if "XP" == row[1] and "Brand X" == row[0]: return False if n > 4: # Contractors are billed in 30 min increments if "Contr." == row[3] and row[4] < 30: return False return True parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60] ] print("PAIRWISE:") for i, pairs in enumerate(AllPairs(parameters, filter_func=is_valid_combination)): print("{:2d}: {}".format(i, pairs)) :Output: .. code:: PAIRWISE: 0: ['Brand X', '98', 'Internal', 'Salaried', 6] 1: ['Brand Y', 'NT', 'Modem', 'Hourly', 6] 2: ['Brand Y', '2000', 'Internal', 'Part-Time', 10] 3: ['Brand X', '2000', 'Modem', 'Contr.', 30] 4: ['Brand X', 'NT', 'Internal', 'Contr.', 60] 5: ['Brand Y', 'XP', 'Modem', 'Salaried', 60] 6: ['Brand X', '98', 'Modem', 'Part-Time', 15] 7: ['Brand Y', 'XP', 'Internal', 'Hourly', 15] 8: ['Brand Y', 'NT', 'Internal', 'Part-Time', 30] 9: ['Brand X', '2000', 'Modem', 'Hourly', 10] 10: ['Brand Y', 'XP', 'Modem', 'Contr.', 30] 11: ['Brand Y', '2000', 'Modem', 'Salaried', 15] 12: ['Brand Y', 'NT', 'Modem', 'Salaried', 10] 13: ['Brand Y', 'XP', 'Modem', 'Part-Time', 6] 14: ['Brand Y', '2000', 'Modem', 'Contr.', 60] Data Source: OrderedDict ==================================== You can use ``collections.OrderedDict`` instance as an argument for ``AllPairs`` constructor. Pairs will be returned as ``collections.namedtuple`` instances. :Sample Code: .. code:: python from collections import OrderedDict from allpairspy import AllPairs parameters = OrderedDict({ "brand": ["Brand X", "Brand Y"], "os": ["98", "NT", "2000", "XP"], "minute": [15, 30, 60], }) print("PAIRWISE:") for i, pairs in enumerate(AllPairs(parameters)): print("{:2d}: {}".format(i, pairs)) :Sample Code: .. code:: PAIRWISE: 0: Pairs(brand='Brand X', os='98', minute=15) 1: Pairs(brand='Brand Y', os='NT', minute=15) 2: Pairs(brand='Brand Y', os='2000', minute=30) 3: Pairs(brand='Brand X', os='XP', minute=30) 4: Pairs(brand='Brand X', os='2000', minute=60) 5: Pairs(brand='Brand Y', os='XP', minute=60) 6: Pairs(brand='Brand Y', os='98', minute=60) 7: Pairs(brand='Brand X', os='NT', minute=60) 8: Pairs(brand='Brand X', os='NT', minute=30) 9: Pairs(brand='Brand X', os='98', minute=30) 10: Pairs(brand='Brand X', os='XP', minute=15) 11: Pairs(brand='Brand X', os='2000', minute=15) Parameterized testing pairwise by using pytest ==================================================================== Parameterized testing: value matrix ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Sample Code: .. code:: python import pytest from allpairspy import AllPairs def function_to_be_tested(brand, operating_system, minute) -> bool: # do something return True class TestParameterized(object): @pytest.mark.parametrize(["brand", "operating_system", "minute"], [ values for values in AllPairs([ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], [10, 15, 30, 60] ]) ]) def test(self, brand, operating_system, minute): assert function_to_be_tested(brand, operating_system, minute) :Output: .. code:: $ py.test test_parameterize.py -v ============================= test session starts ============================== ... collected 16 items test_parameterize.py::TestParameterized::test[Brand X-98-10] PASSED [ 6%] test_parameterize.py::TestParameterized::test[Brand Y-NT-10] PASSED [ 12%] test_parameterize.py::TestParameterized::test[Brand Y-2000-15] PASSED [ 18%] test_parameterize.py::TestParameterized::test[Brand X-XP-15] PASSED [ 25%] test_parameterize.py::TestParameterized::test[Brand X-2000-30] PASSED [ 31%] test_parameterize.py::TestParameterized::test[Brand Y-XP-30] PASSED [ 37%] test_parameterize.py::TestParameterized::test[Brand Y-98-60] PASSED [ 43%] test_parameterize.py::TestParameterized::test[Brand X-NT-60] PASSED [ 50%] test_parameterize.py::TestParameterized::test[Brand X-NT-30] PASSED [ 56%] test_parameterize.py::TestParameterized::test[Brand X-98-30] PASSED [ 62%] test_parameterize.py::TestParameterized::test[Brand X-XP-60] PASSED [ 68%] test_parameterize.py::TestParameterized::test[Brand X-2000-60] PASSED [ 75%] test_parameterize.py::TestParameterized::test[Brand X-2000-10] PASSED [ 81%] test_parameterize.py::TestParameterized::test[Brand X-XP-10] PASSED [ 87%] test_parameterize.py::TestParameterized::test[Brand X-98-15] PASSED [ 93%] test_parameterize.py::TestParameterized::test[Brand X-NT-15] PASSED [100%] Parameterized testing: OrderedDict ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Sample Code: .. code:: python import pytest from allpairspy import AllPairs def function_to_be_tested(brand, operating_system, minute) -> bool: # do something return True class TestParameterized(object): @pytest.mark.parametrize( ["pair"], [ [pair] for pair in AllPairs( OrderedDict( { "brand": ["Brand X", "Brand Y"], "operating_system": ["98", "NT", "2000", "XP"], "minute": [10, 15, 30, 60], } ) ) ], ) def test(self, pair): assert function_to_be_tested(pair.brand, pair.operating_system, pair.minute) Other Examples ================= Other examples could be found in `examples `__ directory. Installation ------------ Installation: pip ================================== :: pip install allpairspy Installation: apt ================================== You can install the package by ``apt`` via a Personal Package Archive (`PPA `__): :: sudo add-apt-repository ppa:thombashi/ppa sudo apt update sudo apt install python3-allpairspy Known issues ------------ * Not optimal - there are tools that can create smaller set covering all the pairs. However, they are missing some other important features and/or do not integrate well with Python. * Lousy written filtering function may lead to full permutation of parameters. * Version 2.0 has become slower (a side-effect of introducing ability to produce n-wise combinations). Dependencies ------------ Python 3.7+ no external dependencies. Sponsors ------------ .. image:: https://avatars.githubusercontent.com/u/3658062?s=48&v=4 :target: https://github.com/b4tman :alt: Dmitry Belyaev (b4tman) .. image:: https://avatars.githubusercontent.com/u/44389260?s=48&u=6da7176e51ae2654bcfd22564772ef8a3bb22318&v=4 :target: https://github.com/chasbecker :alt: Charles Becker (chasbecker) .. image:: https://avatars.githubusercontent.com/u/46711571?s=48&u=57687c0e02d5d6e8eeaf9177f7b7af4c9f275eb5&v=4 :target: https://github.com/Arturi0 :alt: Arturi0 `Become a sponsor `__ allpairspy-2.5.1/allpairspy/000077500000000000000000000000001445222343200160605ustar00rootroot00000000000000allpairspy-2.5.1/allpairspy/__init__.py000066400000000000000000000002621445222343200201710ustar00rootroot00000000000000from .__version__ import ( __author__, __author_email__, __license__, __maintainer__, __maintainer_email__, __version__, ) from .allpairs import AllPairs allpairspy-2.5.1/allpairspy/__version__.py000066400000000000000000000003561445222343200207170ustar00rootroot00000000000000__author__ = "MetaCommunications Engineering" __author_email__ = "metacomm@users.sourceforge.net" __maintainer__ = "Tsuyoshi Hombashi" __maintainer_email__ = "tsuyoshi.hombashi@gmail.com" __license__ = "MIT License" __version__ = "2.5.1" allpairspy-2.5.1/allpairspy/allpairs.py000066400000000000000000000167241445222343200202530ustar00rootroot00000000000000from collections import OrderedDict, namedtuple from functools import cmp_to_key, reduce from itertools import combinations from .pairs_storage import PairsStorage, key class Item: @property def id(self): return self.__item_id @property def value(self): return self.__value @property def weights(self): return self.__weights def __init__(self, item_id, value): self.__item_id = item_id self.__value = value self.set_weights([]) def __str__(self): return str(self.__dict__) def set_weights(self, weights): self.__weights = weights def get_max_combination_number(prameter_matrix, n): param_len_list = [len(value_list) for value_list in prameter_matrix] return sum([reduce(lambda x, y: x * y, z) for z in combinations(param_len_list, n)]) def cmp_item(lhs, rhs): if lhs.weights == rhs.weights: return 0 return -1 if lhs.weights < rhs.weights else 1 class AllPairs: def __init__(self, parameters, filter_func=lambda x: True, previously_tested=None, n=2): """ TODO: check that input arrays are: - (optional) has no duplicated values inside single array / or compress such values """ if not previously_tested: previously_tested = [[]] self.__validate_parameter(parameters) self.__is_ordered_dict_param = isinstance(parameters, OrderedDict) self.__param_name_list = self.__extract_param_name_list(parameters) self.__pairs_class = namedtuple("Pairs", self.__param_name_list) self.__filter_func = filter_func self.__n = n self.__pairs = PairsStorage(n) value_matrix = self.__extract_value_matrix(parameters) self.__max_unique_pairs_expected = get_max_combination_number(value_matrix, n) self.__working_item_matrix = self.__get_working_item_matrix(value_matrix) for arr in previously_tested: if not arr: continue if len(arr) != len(self.__working_item_matrix): raise RuntimeError("previously tested combination is not complete") if not self.__filter_func(arr): raise ValueError("invalid tested combination is provided") tested = [] for i, val in enumerate(arr): idxs = [ Item(item.id, 0) for item in self.__working_item_matrix[i] if item.value == val ] if len(idxs) != 1: raise ValueError( "value from previously tested combination is not " "found in the parameters or found more than " "once" ) tested.append(idxs[0]) self.__pairs.add_sequence(tested) def __iter__(self): return self def next(self): return self.__next__() def __next__(self): assert len(self.__pairs) <= self.__max_unique_pairs_expected if len(self.__pairs) == self.__max_unique_pairs_expected: # no reasons to search further - all pairs are found raise StopIteration() previous_unique_pairs_count = len(self.__pairs) chosen_item_list = [None] * len(self.__working_item_matrix) indexes = [None] * len(self.__working_item_matrix) direction = 1 i = 0 while -1 < i < len(self.__working_item_matrix): if direction == 1: # move forward self.__resort_working_array(chosen_item_list[:i], i) indexes[i] = 0 elif direction == 0 or direction == -1: # scan current array or go back indexes[i] += 1 if indexes[i] >= len(self.__working_item_matrix[i]): direction = -1 if i == 0: raise StopIteration() i += direction continue direction = 0 else: raise ValueError(f"next(): unknown 'direction' code '{direction}'") chosen_item_list[i] = self.__working_item_matrix[i][indexes[i]] if self.__filter_func(self.__get_values(chosen_item_list[: i + 1])): assert direction > -1 direction = 1 else: direction = 0 i += direction if len(self.__working_item_matrix) != len(chosen_item_list): raise StopIteration() self.__pairs.add_sequence(chosen_item_list) if len(self.__pairs) == previous_unique_pairs_count: # could not find new unique pairs - stop raise StopIteration() # replace returned array elements with real values and return it return self.__get_iteration_value(chosen_item_list) def __validate_parameter(self, value): if isinstance(value, OrderedDict): for parameter_list in value.values(): if not parameter_list: raise ValueError("each parameter arrays must have at least one item") return if len(value) < 2: raise ValueError("must provide more than one option") for parameter_list in value: if not parameter_list: raise ValueError("each parameter arrays must have at least one item") def __resort_working_array(self, chosen_item_list, num): for item in self.__working_item_matrix[num]: data_node = self.__pairs.get_node_info(item) new_combs = [ # numbers of new combinations to be created if this item is # appended to array {key(z) for z in combinations(chosen_item_list + [item], i + 1)} - self.__pairs.get_combs()[i] for i in range(0, self.__n) ] # weighting the node node that creates most of new pairs is the best weights = [-len(new_combs[-1])] # less used outbound connections most likely to produce more new # pairs while search continues weights.extend( [len(data_node.out)] + [len(x) for x in reversed(new_combs[:-1])] + [-data_node.counter] # less used node is better ) # otherwise we will prefer node with most of free inbound # connections; somehow it works out better ;) weights.append(-len(data_node.in_)) item.set_weights(weights) self.__working_item_matrix[num].sort(key=cmp_to_key(cmp_item)) def __get_working_item_matrix(self, parameter_matrix): return [ [ Item(f"a{param_idx:d}v{value_idx:d}", value) for value_idx, value in enumerate(value_list) ] for param_idx, value_list in enumerate(parameter_matrix) ] @staticmethod def __get_values(item_list): return [item.value for item in item_list] def __get_iteration_value(self, item_list): if not self.__param_name_list: return [item.value for item in item_list] return self.__pairs_class(*[item.value for item in item_list]) def __extract_param_name_list(self, parameters): if not self.__is_ordered_dict_param: return [] return list(parameters) def __extract_value_matrix(self, parameters): if not self.__is_ordered_dict_param: return parameters return [v for v in parameters.values()] allpairspy-2.5.1/allpairspy/pairs_storage.py000066400000000000000000000032631445222343200213000ustar00rootroot00000000000000from itertools import combinations class Node: @property def id(self): return self.__node_id @property def counter(self): return self.__counter def __init__(self, node_id): self.__node_id = node_id self.__counter = 0 self.in_ = set() self.out = set() def __str__(self): return str(self.__dict__) def inc_counter(self): self.__counter += 1 key_cache = {} def key(items): if items in key_cache: return key_cache[items] key_value = tuple([x.id for x in items]) key_cache[items] = key_value return key_value class PairsStorage: def __init__(self, n): self.__n = n self.__nodes = {} self.__combs_arr = [set() for _i in range(n)] def __len__(self): return len(self.__combs_arr[-1]) def add_sequence(self, sequence): for i in range(1, self.__n + 1): for combination in combinations(sequence, i): self.__add_combination(combination) def get_node_info(self, item): return self.__nodes.get(item.id, Node(item.id)) def get_combs(self): return self.__combs_arr def __add_combination(self, combination): n = len(combination) assert n > 0 self.__combs_arr[n - 1].add(key(combination)) if n == 1 and combination[0].id not in self.__nodes: self.__nodes[combination[0].id] = Node(combination[0].id) return ids = [x.id for x in combination] for i, id in enumerate(ids): curr = self.__nodes[id] curr.inc_counter() curr.in_.update(ids[:i]) curr.out.update(ids[i + 1 :]) allpairspy-2.5.1/examples/000077500000000000000000000000001445222343200155165ustar00rootroot00000000000000allpairspy-2.5.1/examples/compare_to_others.py000077500000000000000000000021111445222343200216020ustar00rootroot00000000000000#!/usr/bin/env python3 from allpairspy import AllPairs """ Provided to make it easier to compare efficiency with other tools as per http://pairwise.org/tools.asp Current output is: 3^4: produces 9 rows 3^13: produces 17 rows 4^15 * 3^17 * 2^29: produces 37 rows 4^1 * 3^39 * 2^35: produces 27 rows 3^100: produces 29 rows 2^100: produces 15 rows 10^20: produces 219 rows 10^10: produces 172 rows """ def get_arrays(dimensions): opts = [] for d in dimensions: r = [] for _i in range(d[1]): r.append(range(d[0])) opts += r return opts def print_result(dimensions): header_list = [] for d in dimensions: header_list.append("%i^%i" % d) pairwise = AllPairs(get_arrays(dimensions)) n = len(list(pairwise)) print("{:s}: produces {:d} rows".format(" * ".join(header_list), n)) print_result(((3, 4),)) print_result(((3, 13),)) print_result(((4, 15), (3, 17), (2, 29))) print_result(((4, 1), (3, 39), (2, 35))) print_result(((3, 100),)) print_result(((2, 100),)) print_result(((10, 20),)) print_result(((10, 10),)) allpairspy-2.5.1/examples/example1.1.py000077500000000000000000000010251445222343200177440ustar00rootroot00000000000000#!/usr/bin/env python3 """ Demo of the basic functionality - just getting pairwise/n-wise combinations """ from allpairspy import AllPairs parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] # sample parameters are is taken from # http://www.stsc.hill.af.mil/consulting/sw_testing/improvement/cst.html print("PAIRWISE:") for i, pairs in enumerate(AllPairs(parameters)): print(f"{i:2d}: {pairs}") allpairspy-2.5.1/examples/example1.2.py000077500000000000000000000010341445222343200177450ustar00rootroot00000000000000#!/usr/bin/env python3 """ Demo of the basic functionality - just getting pairwise/n-wise combinations """ from allpairspy import AllPairs parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] # sample parameters are is taken from # http://www.stsc.hill.af.mil/consulting/sw_testing/improvement/cst.html print("TRIPLEWISE:") for i, pairs in enumerate(AllPairs(parameters, n=3)): print(f"{i:2d}: {pairs}") allpairspy-2.5.1/examples/example1.3.py000077500000000000000000000013541445222343200177530ustar00rootroot00000000000000#!/usr/bin/env python3 """ Demo of the basic functionality - just getting pairwise combinations and skipping previously tested pairs. """ from allpairspy import AllPairs parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] # sample parameters are is taken from # http://www.stsc.hill.af.mil/consulting/sw_testing/improvement/cst.html tested = [ ["Brand X", "98", "Modem", "Hourly", 10], ["Brand X", "98", "Modem", "Hourly", 15], ["Brand Y", "NT", "Internal", "Part-Time", 10], ] print("PAIRWISE:") for i, pairs in enumerate(AllPairs(parameters, previously_tested=tested)): print(f"{i:2d}: {pairs}") allpairspy-2.5.1/examples/example2.1.py000077500000000000000000000024211445222343200177460ustar00rootroot00000000000000#!/usr/bin/env python3 """ Demo of filtering capabilities """ from allpairspy import AllPairs def is_valid_combination(row): """ This is a filtering function. Filtering functions should return True if combination is valid and False otherwise. Test row that is passed here can be incomplete. To prevent search for unnecessary items filtering function is executed with found subset of data to validate it. """ n = len(row) if n > 1: # Brand Y does not support Windows 98 if "98" == row[1] and "Brand Y" == row[0]: return False # Brand X does not work with XP if "XP" == row[1] and "Brand X" == row[0]: return False if n > 4: # Contractors are billed in 30 min increments if "Contr." == row[3] and row[4] < 30: return False return True # sample parameters are is taken from # http://www.stsc.hill.af.mil/consulting/sw_testing/improvement/cst.html parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] print("PAIRWISE:") for i, pairs in enumerate(AllPairs(parameters, filter_func=is_valid_combination)): print(f"{i:2d}: {pairs}") allpairspy-2.5.1/examples/example2.2.py000077500000000000000000000030701445222343200177500ustar00rootroot00000000000000#!/usr/bin/env python3 """ Another demo of filtering capabilities. Demonstrates how to use named parameters """ from allpairspy import AllPairs def is_valid_combination(values, names): dictionary = dict(zip(names, values)) """ Should return True if combination is valid and False otherwise. Dictionary that is passed here can be incomplete. To prevent search for unnecessary items filtering function is executed with found subset of data to validate it. """ rules = [ # Brand Y does not support Windows 98 # Brand X does not work with XP # Contractors are billed in 30 min increments lambda d: "98" == d["os"] and "Brand Y" == d["brand"], lambda d: "XP" == d["os"] and "Brand X" == d["brand"], lambda d: "Contr." == d["employee"] and d["increment"] < 30, ] for rule in rules: try: if rule(dictionary): return False except KeyError: pass return True # sample parameters are is taken from # http://www.stsc.hill.af.mil/consulting/sw_testing/improvement/cst.html parameters = [ ("brand", ["Brand X", "Brand Y"]), ("os", ["98", "NT", "2000", "XP"]), ("network", ["Internal", "Modem"]), ("employee", ["Salaried", "Hourly", "Part-Time", "Contr."]), ("increment", [6, 10, 15, 30, 60]), ] pairwise = AllPairs( [x[1] for x in parameters], filter_func=lambda values: is_valid_combination(values, [x[0] for x in parameters]), ) print("PAIRWISE:") for i, pairs in enumerate(pairwise): print(f"{i:2d}: {pairs}") allpairspy-2.5.1/examples/example_ordered_dict.py000066400000000000000000000005351445222343200222350ustar00rootroot00000000000000#!/usr/bin/env python3 from collections import OrderedDict from allpairspy import AllPairs parameters = OrderedDict( { "brand": ["Brand X", "Brand Y"], "os": ["98", "NT", "2000", "XP"], "minute": [15, 30, 60], } ) print("PAIRWISE:") for i, pairs in enumerate(AllPairs(parameters)): print(f"{i:2d}: {pairs}") allpairspy-2.5.1/examples/test_parameterize.py000066400000000000000000000012451445222343200216210ustar00rootroot00000000000000#!/usr/bin/env python3 """ .. codeauthor:: Tsuyoshi Hombashi """ import pytest from allpairspy import AllPairs def function_to_be_tested(brand: str, operating_system: str, minute: int) -> bool: # do something return True class TestParameterized: @pytest.mark.parametrize( ["brand", "operating_system", "minute"], [ values for values in AllPairs( [["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], [10, 15, 30, 60]] ) ], ) def test(self, brand, operating_system, minute): assert function_to_be_tested(brand, operating_system, minute) allpairspy-2.5.1/pylama.ini000066400000000000000000000005651445222343200156720ustar00rootroot00000000000000[pylama] skip = .eggs/*,.tox/*,*/.env/*,build/*,node_modules/*,_sandbox/*,build/*,docs/conf.py [pylama:pycodestyle] max_line_length = 100 # E203: whitespace before ':' (for black) # W503: line break before binary operator (for black) ignore = E203,W503 [pylama:pylint] max_line_length = 100 [pylama:*/__init__.py] # W0611: imported but unused [pyflakes] ignore = W0611 allpairspy-2.5.1/pyproject.toml000066400000000000000000000017261445222343200166220ustar00rootroot00000000000000[build-system] requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [tool.black] line-length = 100 exclude = ''' /( \.eggs | \.git | \.mypy_cache | \.tox | \.venv | \.pytype | _build | buck-out | build | dist )/ | docs/conf.py ''' target-version = ['py37', 'py38', 'py39', 'py310'] [tool.coverage.run] source = ['allpairspy'] branch = true [tool.coverage.report] show_missing = true precision = 1 exclude_lines = [ 'except ImportError', 'raise NotImplementedError', 'pass', 'ABCmeta', 'abstractmethod', 'abstractproperty', 'abstractclassmethod', 'warnings.warn', ] [tool.isort] known_third_party = [ ] include_trailing_comma = true line_length = 100 lines_after_imports = 2 multi_line_output = 3 skip_glob = [ '*/.eggs/*', '*/.pytype/*', '*/.tox/*', ] [tool.pytest.ini_options] testpaths = [ "tests", ] md_report = true md_report_verbose = 0 md_report_color = "auto" allpairspy-2.5.1/requirements/000077500000000000000000000000001445222343200164235ustar00rootroot00000000000000allpairspy-2.5.1/requirements/requirements.txt000066400000000000000000000000001445222343200216750ustar00rootroot00000000000000allpairspy-2.5.1/requirements/test_requirements.txt000066400000000000000000000000441445222343200227440ustar00rootroot00000000000000pytest>=6.0.1 pytest-md-report>=0.3 allpairspy-2.5.1/setup.py000066400000000000000000000052431445222343200154160ustar00rootroot00000000000000import os.path import setuptools MODULE_NAME = "allpairspy" REPOSITORY_URL = f"https://github.com/thombashi/{MODULE_NAME:s}" REQUIREMENT_DIR = "requirements" pkg_info = {} def get_release_command_class(): try: from releasecmd import ReleaseCommand except ImportError: return {} return {"release": ReleaseCommand} with open(os.path.join(MODULE_NAME, "__version__.py")) as f: exec(f.read(), pkg_info) with open("README.rst", encoding="utf8") as fp: long_description = fp.read() with open(os.path.join(REQUIREMENT_DIR, "requirements.txt")) as f: install_requires = [line.strip() for line in f if line.strip()] with open(os.path.join(REQUIREMENT_DIR, "test_requirements.txt")) as f: tests_requires = [line.strip() for line in f if line.strip()] setuptools.setup( name=MODULE_NAME, version=pkg_info["__version__"], url=REPOSITORY_URL, author=pkg_info["__author__"], author_email=pkg_info["__author_email__"], description="Pairwise test combinations generator", long_description=long_description, long_description_content_type="text/x-rst", license=pkg_info["__license__"], maintainer=pkg_info["__maintainer__"], maintainer_email=pkg_info["__maintainer_email__"], packages=setuptools.find_packages(exclude=["tests*"]), project_urls={ "Source": REPOSITORY_URL, "Tracker": f"{REPOSITORY_URL:s}/issues", }, python_requires=">=3.7", install_requires=install_requires, extras_require={"test": tests_requires}, classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Testing", "Topic :: Utilities", ], cmdclass=get_release_command_class(), ) allpairspy-2.5.1/tests/000077500000000000000000000000001445222343200150425ustar00rootroot00000000000000allpairspy-2.5.1/tests/test_allpairs.py000066400000000000000000000243071445222343200202700ustar00rootroot00000000000000""" .. codeauthor:: Tsuyoshi Hombashi """ from collections import OrderedDict from allpairspy import AllPairs class Test_pairewise_OrderedDict: def test_normal(self): parameters = OrderedDict( {"brand": ["Brand X", "Brand Y"], "os": ["NT", "2000", "XP"], "minute": [15, 30, 60]} ) for pairs in AllPairs(parameters): assert pairs.brand == "Brand X" assert pairs.os == "NT" assert pairs.minute == 15 break assert len(list(AllPairs(parameters))) == 9 class Test_pairewise_list: # example1.1.py def test_normal(self): parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] assert list(AllPairs(parameters)) == [ ["Brand X", "98", "Internal", "Salaried", 6], ["Brand Y", "NT", "Modem", "Hourly", 6], ["Brand Y", "2000", "Internal", "Part-Time", 10], ["Brand X", "XP", "Modem", "Contr.", 10], ["Brand X", "2000", "Modem", "Part-Time", 15], ["Brand Y", "XP", "Internal", "Hourly", 15], ["Brand Y", "98", "Modem", "Salaried", 30], ["Brand X", "NT", "Internal", "Contr.", 30], ["Brand X", "98", "Internal", "Hourly", 60], ["Brand Y", "2000", "Modem", "Contr.", 60], ["Brand Y", "NT", "Modem", "Salaried", 60], ["Brand Y", "XP", "Modem", "Part-Time", 60], ["Brand Y", "2000", "Modem", "Hourly", 30], ["Brand Y", "98", "Modem", "Contr.", 15], ["Brand Y", "XP", "Modem", "Salaried", 15], ["Brand Y", "NT", "Modem", "Part-Time", 15], ["Brand Y", "XP", "Modem", "Part-Time", 30], ["Brand Y", "98", "Modem", "Part-Time", 6], ["Brand Y", "2000", "Modem", "Salaried", 6], ["Brand Y", "98", "Modem", "Salaried", 10], ["Brand Y", "XP", "Modem", "Contr.", 6], ["Brand Y", "NT", "Modem", "Hourly", 10], ] class Test_triplewise: # example1.2.py def test_normal(self): parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] assert list(AllPairs(parameters, n=3)) == [ ["Brand X", "98", "Internal", "Salaried", 6], ["Brand Y", "NT", "Modem", "Hourly", 6], ["Brand Y", "2000", "Modem", "Part-Time", 10], ["Brand X", "XP", "Internal", "Contr.", 10], ["Brand X", "XP", "Modem", "Part-Time", 6], ["Brand Y", "2000", "Internal", "Hourly", 15], ["Brand Y", "NT", "Internal", "Salaried", 10], ["Brand X", "98", "Modem", "Contr.", 15], ["Brand X", "98", "Modem", "Hourly", 10], ["Brand Y", "NT", "Modem", "Contr.", 30], ["Brand X", "XP", "Internal", "Hourly", 30], ["Brand X", "2000", "Modem", "Salaried", 30], ["Brand Y", "2000", "Internal", "Contr.", 6], ["Brand Y", "NT", "Internal", "Part-Time", 60], ["Brand Y", "XP", "Modem", "Salaried", 15], ["Brand X", "98", "Modem", "Part-Time", 60], ["Brand X", "XP", "Modem", "Salaried", 60], ["Brand X", "2000", "Internal", "Part-Time", 15], ["Brand X", "2000", "Modem", "Contr.", 60], ["Brand X", "98", "Modem", "Salaried", 10], ["Brand X", "98", "Modem", "Part-Time", 30], ["Brand X", "NT", "Modem", "Part-Time", 10], ["Brand Y", "NT", "Modem", "Salaried", 60], ["Brand Y", "NT", "Modem", "Hourly", 15], ["Brand Y", "NT", "Modem", "Hourly", 30], ["Brand Y", "NT", "Modem", "Hourly", 60], ["Brand Y", "NT", "Modem", "Hourly", 10], ] class Test_pairewise_w_tested: # example1.3.py def test_normal(self): parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] tested = [ ["Brand X", "98", "Modem", "Hourly", 10], ["Brand X", "98", "Modem", "Hourly", 15], ["Brand Y", "NT", "Internal", "Part-Time", 10], ] assert list(AllPairs(parameters, previously_tested=tested)) == [ ["Brand Y", "2000", "Modem", "Salaried", 6], ["Brand X", "XP", "Internal", "Contr.", 6], ["Brand Y", "XP", "Modem", "Contr.", 30], ["Brand X", "2000", "Internal", "Part-Time", 30], ["Brand Y", "98", "Internal", "Salaried", 60], ["Brand X", "NT", "Modem", "Salaried", 60], ["Brand Y", "XP", "Internal", "Hourly", 15], ["Brand Y", "NT", "Modem", "Hourly", 30], ["Brand Y", "2000", "Modem", "Part-Time", 15], ["Brand Y", "2000", "Modem", "Contr.", 10], ["Brand Y", "XP", "Modem", "Salaried", 10], ["Brand Y", "98", "Modem", "Part-Time", 6], ["Brand Y", "NT", "Modem", "Contr.", 15], ["Brand Y", "98", "Modem", "Contr.", 30], ["Brand Y", "XP", "Modem", "Part-Time", 60], ["Brand Y", "2000", "Modem", "Hourly", 60], ["Brand Y", "NT", "Modem", "Salaried", 30], ["Brand Y", "NT", "Modem", "Salaried", 15], ["Brand Y", "NT", "Modem", "Hourly", 6], ["Brand Y", "NT", "Modem", "Contr.", 60], ] class Test_pairewise_filter: def test_normal_example21(self): # example2.1.py parameters = [ ["Brand X", "Brand Y"], ["98", "NT", "2000", "XP"], ["Internal", "Modem"], ["Salaried", "Hourly", "Part-Time", "Contr."], [6, 10, 15, 30, 60], ] def is_valid_combination(row): """ Should return True if combination is valid and False otherwise. Test row that is passed here can be incomplete. To prevent search for unnecessary items filtering function is executed with found subset of data to validate it. """ n = len(row) if n > 1: # Brand Y does not support Windows 98 if "98" == row[1] and "Brand Y" == row[0]: return False # Brand X does not work with XP if "XP" == row[1] and "Brand X" == row[0]: return False if n > 4: # Contractors are billed in 30 min increments if "Contr." == row[3] and row[4] < 30: return False return True assert list(AllPairs(parameters, filter_func=is_valid_combination)) == [ ["Brand X", "98", "Internal", "Salaried", 6], ["Brand Y", "NT", "Modem", "Hourly", 6], ["Brand Y", "2000", "Internal", "Part-Time", 10], ["Brand X", "2000", "Modem", "Contr.", 30], ["Brand X", "NT", "Internal", "Contr.", 60], ["Brand Y", "XP", "Modem", "Salaried", 60], ["Brand X", "98", "Modem", "Part-Time", 15], ["Brand Y", "XP", "Internal", "Hourly", 15], ["Brand Y", "NT", "Internal", "Part-Time", 30], ["Brand X", "2000", "Modem", "Hourly", 10], ["Brand Y", "XP", "Modem", "Contr.", 30], ["Brand Y", "2000", "Modem", "Salaried", 15], ["Brand Y", "NT", "Modem", "Salaried", 10], ["Brand Y", "XP", "Modem", "Part-Time", 6], ["Brand Y", "2000", "Modem", "Contr.", 60], ] def test_normal_example22(self): # example2.2.py parameters = [ ("brand", ["Brand X", "Brand Y"]), ("os", ["98", "NT", "2000", "XP"]), ("network", ["Internal", "Modem"]), ("employee", ["Salaried", "Hourly", "Part-Time", "Contr."]), ("increment", [6, 10, 15, 30, 60]), ] def is_valid_combination(values, names): dictionary = dict(zip(names, values)) """ Should return True if combination is valid and False otherwise. Dictionary that is passed here can be incomplete. To prevent search for unnecessary items filtering function is executed with found subset of data to validate it. """ rules = [ # Brand Y does not support Windows 98 # Brand X does not work with XP # Contractors are billed in 30 min increments lambda d: "98" == d["os"] and "Brand Y" == d["brand"], lambda d: "XP" == d["os"] and "Brand X" == d["brand"], lambda d: "Contr." == d["employee"] and d["increment"] < 30, ] for rule in rules: try: if rule(dictionary): return False except KeyError: pass return True assert list( AllPairs( [x[1] for x in parameters], filter_func=lambda values: is_valid_combination(values, [x[0] for x in parameters]), ) ) == [ ["Brand X", "98", "Internal", "Salaried", 6], ["Brand Y", "NT", "Modem", "Hourly", 6], ["Brand Y", "2000", "Internal", "Part-Time", 10], ["Brand X", "2000", "Modem", "Contr.", 30], ["Brand X", "NT", "Internal", "Contr.", 60], ["Brand Y", "XP", "Modem", "Salaried", 60], ["Brand X", "98", "Modem", "Part-Time", 15], ["Brand Y", "XP", "Internal", "Hourly", 15], ["Brand Y", "NT", "Internal", "Part-Time", 30], ["Brand X", "2000", "Modem", "Hourly", 10], ["Brand Y", "XP", "Modem", "Contr.", 30], ["Brand Y", "2000", "Modem", "Salaried", 15], ["Brand Y", "NT", "Modem", "Salaried", 10], ["Brand Y", "XP", "Modem", "Part-Time", 6], ["Brand Y", "2000", "Modem", "Contr.", 60], ] allpairspy-2.5.1/tox.ini000066400000000000000000000016341445222343200152170ustar00rootroot00000000000000[tox] envlist = py{37,38,39,310,311} pypy3 build cov fmt lint [testenv] extras = test commands = pytest {posargs} [testenv:build] deps = build>=0.10 twine wheel commands = python -m build twine check dist/*.whl dist/*.tar.gz [testenv:clean] skip_install = true deps = cleanpy>=0.4 commands = cleanpy --all --exclude-envs . [testenv:cov] extras = test deps = coverage[toml] commands = coverage run -m pytest {posargs:-vv} coverage report -m [testenv:fmt] skip_install = true deps = autoflake>=2 black>=23.1 isort>=5 commands = black setup.py examples tests allpairspy autoflake --in-place --recursive --remove-all-unused-imports --ignore-init-module-imports . isort . [testenv:lint] skip_install = true deps = codespell pylama commands = codespell allpairspy examples tests -q2 --check-filenames pylama