### Install crosszip using pip or uv Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Install the crosszip package using either pip or uv package managers. ```bash pip install crosszip ``` ```bash uv add crosszip ``` -------------------------------- ### Generate Labels using crosszip Source: https://github.com/indrajeetpatil/crosszip/blob/main/README.md Use crosszip to apply a function to all possible combinations of elements from multiple iterables. Ensure the crosszip library is installed. ```python from crosszip import crosszip def create_label(category, subcategory, version): return f"{category}_{subcategory}_v{version}" categories = ["cat", "dog"] subcategories = ["small", "large"] versions = ["1.0", "2.0"] labels = crosszip(create_label, categories, subcategories, versions) print(labels) ``` -------------------------------- ### Parametrize Pytest with crosszip_parametrize Source: https://github.com/indrajeetpatil/crosszip/blob/main/README.md Utilize the @pytest.mark.crosszip_parametrize marker to run tests with all combinations of provided parameter values. This requires pytest and crosszip to be installed. ```python import math import crosszip import pytest @pytest.mark.crosszip_parametrize( "base", [2, 10], "exponent", [-1, 0, 1], ) def test_power_function(base, exponent): result = math.pow(base, exponent) assert result == base**exponent print("Tests executed successfully.") ``` -------------------------------- ### Handling Custom Crosszip Exceptions Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Shows how to import and catch specific custom exceptions provided by the crosszip package. ```python from crosszip.exceptions import ( CrosszipError, CrosszipTypeError, CrosszipValueError, ) # CrosszipError is the base exception for all crosszip errors # CrosszipTypeError inherits from CrosszipError and TypeError # CrosszipValueError inherits from CrosszipError and ValueError try: # Some crosszip operation that might fail pass except CrosszipTypeError as e: print(f"Type error: {e}") except CrosszipValueError as e: print(f"Value error: {e}") except CrosszipError as e: print(f"Crosszip error: {e}") ``` -------------------------------- ### Crosszip with tuples and a mathematical function Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Demonstrates using crosszip with tuples and a simple mathematical function. The function should accept arguments corresponding to the elements in the tuples. ```python from crosszip import crosszip # With tuples and a mathematical function def add(a, b): return a + b result = crosszip(add, (1, 2), (10, 20)) print(result) # Output: [11, 21, 12, 22] ``` -------------------------------- ### Pytest: Parametrize tests with crosszip_parametrize (three parameters) Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Demonstrates using `@pytest.mark.crosszip_parametrize` with three parameters, automatically generating 8 test cases (2x2x2 combinations). ```python import math import pytest # Three parameters: generates 8 test cases (2 × 2 × 2) @pytest.mark.crosszip_parametrize( "x", [1, 2], "y", [3, 4], "z", [5, 6], ) def test_three_params(x, y, z): assert (x, y, z) in [ (1, 3, 5), (1, 3, 6), (1, 4, 5), (1, 4, 6), (2, 3, 5), (2, 3, 6), (2, 4, 5), (2, 4, 6), ] ``` -------------------------------- ### Pytest: Parametrize tests with crosszip_parametrize (single parameter) Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Shows how to use `@pytest.mark.crosszip_parametrize` with a single parameter, generating 3 test cases for the provided list of values. ```python import math import pytest # Single parameter @pytest.mark.crosszip_parametrize( "value", [1, 2, 3], ) def test_single_param(value): assert value in [1, 2, 3] # This generates 3 test cases ``` -------------------------------- ### Pytest: Parametrize tests with crosszip_parametrize (two parameters) Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Uses the `@pytest.mark.crosszip_parametrize` marker to run a test function with all combinations of two parameters. This generates 6 test cases for the given inputs. ```python import math import pytest # Basic usage: Test all combinations of base and exponent values @pytest.mark.crosszip_parametrize( "base", [2, 10], "exponent", [-1, 0, 1], ) def test_power_function(base, exponent): result = math.pow(base, exponent) assert result == base ** exponent # This generates 6 test cases: (2,-1), (2,0), (2,1), (10,-1), (10,0), (10,1) ``` -------------------------------- ### Pytest Error Handling: No parameters provided Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Illustrates an error case for `@pytest.mark.crosszip_parametrize` where no parameters are provided, resulting in a `ValueError`. ```python import pytest # Error: Parameter names and values must be provided @pytest.mark.crosszip_parametrize() def test_no_params(): pass # Raises: ValueError: Parameter names and values must be provided. ``` -------------------------------- ### Crosszip with a generator, list, and string Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Illustrates using crosszip with a generator, a list, and a list of strings. The provided lambda function concatenates elements from all three iterables. ```python from crosszip import crosszip # With a generator def gen(): yield 1 yield 2 concat = lambda a, b, c: f"{a}-{b}-{c}" result = crosszip(concat, gen(), [3, 4], ["a", "b"]) print(result) # Output: ['1-3-a', '1-3-b', '1-4-a', '1-4-b', '2-3-a', '2-3-b', '2-4-a', '2-4-b'] ``` -------------------------------- ### Crosszip with range and string Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Combines a range object and a string using crosszip with a lambda function for string formatting. The lambda function processes elements from both iterables. ```python from crosszip import crosszip # With range and string result = crosszip(lambda a, b: f"{a}-{b}", range(1, 3), "ab") print(result) # Output: ['1-a', '1-b', '2-a', '2-b'] ``` -------------------------------- ### Crosszip with sets Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Applies a function to combinations of elements from sets. Note that the order of results is not guaranteed due to the unordered nature of sets. ```python from crosszip import crosszip # With sets (note: order may vary due to set unordered nature) concat = lambda a, b, c: f"{a}-{b}-{c}" result = crosszip(concat, {1, 2}, {"x", "y"}, {"foo", "bar"}) # Results contain all 8 combinations, but order is not guaranteed ``` -------------------------------- ### Basic crosszip usage with a custom function Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Applies a custom function to all combinations of elements from provided iterables. Ensure the function signature matches the number of iterables. ```python from crosszip import crosszip # Basic usage: Apply a function to all combinations of elements def create_label(category, subcategory, version): return f"{category}_{subcategory}_v{version}" categories = ["cat", "dog"] subcategories = ["small", "large"] versions = ["1.0", "2.0"] labels = crosszip(create_label, categories, subcategories, versions) print(labels) # Output: ['cat_small_v1.0', 'cat_small_v2.0', 'cat_large_v1.0', 'cat_large_v2.0', # 'dog_small_v1.0', 'dog_small_v2.0', 'dog_large_v1.0', 'dog_large_v2.0'] ``` -------------------------------- ### Pytest Error Handling: Missing parameter values Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Demonstrates an error scenario where a parameter name is provided without corresponding values, triggering a `ValueError`. ```python import pytest # Error: Each parameter name must have a corresponding list of values @pytest.mark.crosszip_parametrize( "x", [1, 2], "y", # Missing values for y ) def test_missing_values(x, y): pass # Raises: ValueError: Each parameter name must have a corresponding list of values. ``` -------------------------------- ### Pytest Error Handling: Empty parameter values Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Illustrates an error when parameter values are an empty sequence (e.g., an empty list), which raises a `TypeError`. Parameter values must be non-empty sequences. ```python import pytest # Error: All parameter values must be non-empty sequences @pytest.mark.crosszip_parametrize( "x", [], # Empty list "y", [3, 4], ) def test_empty_values(x, y): pass # Raises: TypeError: All parameter values must be non-empty sequences. ``` -------------------------------- ### Triggering a TypeError with crosszip_parametrize Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Demonstrates an invalid usage of crosszip_parametrize where a scalar is passed instead of a sequence. ```python @pytest.mark.crosszip_parametrize( "x", 1, # Not a sequence "y", [3, 4], ) def test_non_sequence(x, y): pass ``` -------------------------------- ### Pytest Error Handling: Invalid parameter name type Source: https://context7.com/indrajeetpatil/crosszip/llms.txt Shows an error case where a parameter name is not a string, leading to a `TypeError`. All parameter names must be strings. ```python import pytest # Error: All parameter names must be strings @pytest.mark.crosszip_parametrize( 123, [1, 2], # 123 is not a string "y", [3, 4], ) def test_invalid_name(x, y): pass # Raises: TypeError: All parameter names must be strings. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.