Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer test cases from input HeroSeries in test_indexes #179

Open
ryangawei opened this issue Sep 7, 2020 · 4 comments
Open

Infer test cases from input HeroSeries in test_indexes #179

ryangawei opened this issue Sep 7, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request testing

Comments

@ryangawei
Copy link

ryangawei commented Sep 7, 2020

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?

@jbesomi
Copy link
Owner

jbesomi commented Sep 8, 2020

Hey @AlfredWGA, I agree with you and it seems a good idea!

The only part that might be tricky is that for some functions we need to pass more than one parameter (see for instance pca in test_indexes).

By the way, we should also test that all functions work when the given Series input is empty and also when it contains nan values. I believe we can unify all these three tests ...

@ryangawei
Copy link
Author

ryangawei commented Sep 8, 2020

The only part that might be tricky is that for some functions we need to pass more than one parameter (see for instance pca in test_indexes).

That can be done by manually adding test cases like

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

And adding empty and nan Series test shouldn't be a problem, I'll work on that. Through this we can keep only one test_indexes.py as mentioned in #128.

@jbesomi
Copy link
Owner

jbesomi commented Sep 8, 2020

Beautiful!

@jbesomi jbesomi added enhancement New feature or request testing labels Sep 8, 2020
@ryangawei
Copy link
Author

ryangawei commented Sep 8, 2020

See #130 for test handling nan, and #157 for new HeroTypes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request testing
Projects
None yet
Development

No branches or pull requests

2 participants