imjoseangel / powerline-k8sstatus

A Powerline segment for showing the status of a K8s context
MIT License
2 stars 0 forks source link

Implement Hypothesis for Testing #11

Closed imjoseangel closed 3 years ago

imjoseangel commented 3 years ago

SUMMARY

Check how to implement Hypothesis for testing

ISSUE TYPE

COMPONENT NAME

Unit Testing

ADDITIONAL INFORMATION

Review documentation here and some examples here

from hypothesis import given, example
from hypothesis.strategies import integers, lists, text, fixed_dictionaries, sampled_from, none, one_of

@given(path=text(), xs=lists(integers()))
def test_diff_lists_equal(path, xs):
    assert list(diff_lists(path, xs, xs)) == []
imjoseangel commented 3 years ago
# Found no testable functions in
# {<powerline_k8sstatus.segments.K8SStatusSegment object at 0x10e228dd0>} from (<module 'powerline_k8sstatus' from '/Users/imjoseangel/.pyenv/versions/3.7.9/Python.framework/Versions/3.7/lib/python3.7/site-packages/powerline_k8sstatus/__init__.py'>,)
imjoseangel commented 3 years ago

hypothesis write --style=pytest kubernetes.config

# This test code was written by the `hypothesis.extra.ghostwriter` module
# and is provided under the Creative Commons Zero public domain dedication.

import kubernetes.config.kube_config
from hypothesis import given, strategies as st

@given(config_file=st.none())
def test_fuzz_list_kube_config_contexts(config_file):
    kubernetes.config.kube_config.list_kube_config_contexts(config_file=config_file)

@given(
    config_file=st.none(),
    context=st.none(),
    client_configuration=st.none(),
    persist_config=st.booleans(),
)
def test_fuzz_load_kube_config(
    config_file, context, client_configuration, persist_config
):
    kubernetes.config.kube_config.load_kube_config(
        config_file=config_file,
        context=context,
        client_configuration=client_configuration,
        persist_config=persist_config,
    )

@given(config_file=st.none(), context=st.none(), persist_config=st.booleans())
def test_fuzz_new_client_from_config(config_file, context, persist_config):
    kubernetes.config.kube_config.new_client_from_config(
        config_file=config_file, context=context, persist_config=persist_config
    )
imjoseangel commented 3 years ago

Close as it is not needed