Skip to content

Infer test cases from input HeroSeries in test_indexes  #179

@ryangawei

Description

@ryangawei

Currently test_indexes save all test cases using hard encoding, by listing all functions and their valid inputs separately, where lots of functions share the same input. With HeroSeries objects as inputs, it seems easy infer a valid input for each of them.

For example, save a allowed_hero_series_type variable for each function,

def InputSeries(allowed_hero_series_type):
...
    def decorator(func):
        func.allowed_hero_series_type = allowed_hero_series_type
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
...

Then iterate all functions through dir(hero) and generate test cases,

# Define the valid inputs for each HeroSeries type
valid_inputs = {
    "TokenSeries": s_tokenized_lists,
    "TextSeries": s_text,
    "VectorSeries": s_numeric_lists
}

test_cases = []
# Find all functions under texthero
func_strs = [s for s in dir(hero) if not s.startswith("__") and s not in {'preprocessing', 'visualization', 'representation', 'nlp', 'stopwords'}]

# Exceptions for test cases in case they need specific inputs
test_case_exceptions = {
    "pca": ["pca", representation.pca, (s_numeric_lists, 0)]
}

for func_str in func_strs:
    if func_str in test_case_exceptions:
            test_cases.append(test_case_exceptions[func_str])
    else:
        func = getattr(hero, func_str)
        if hasattr(func, 'allowed_hero_series_type'):
            if func.allowed_hero_series_type.__name__ in valid_inputs:
                test_cases.append([func_str, func, (valid_inputs[func.allowed_hero_series_type.__name__],)])

Will it make the code cleaner and easier to maintain?

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions