def test_pos_and_keyword(): result = colors('yellow', 'grey', link_color='purple') # not inclusive list print(result) assert 'foreground: yellow' in result assert 'background: grey' in result assert 'link: purple' in result
def test_tuple_dict(): result = colors(*sample, **sampled2) print(result) assert 'foreground: blue' in result assert 'background: purple' in result assert 'link: purple' in result assert 'visited: magenta' in result
def test_one(): result = colors() print(result) assert 'foreground: red' in result assert 'background: blue' in result assert 'link: green' in result assert 'visited: cyan' in result
def test_pos(): result = colors('red', 'blue', 'yellow', 'chartreuse') print(result) assert 'foreground: red' in result assert 'background: blue' in result assert 'link: yellow' in result assert 'visited: chartreuse' in result
def test_tuple2(): result = colors('green', *sample) print(result) assert 'foreground: green' in result assert 'background: blue' in result assert 'link: purple' in result assert 'visited: cyan' in result
def test_pos_key(): result = colors('purple', link_color="magenta") print(result) assert 'foreground: purple' in result assert 'background: blue' in result assert 'link: magenta' in result assert 'visited: cyan' in result
def test_call_tuple(): t = ('red', 'blue', 'yellow', 'chartreuse') result = colors(*t) print(result) assert 'red' in result assert 'blue' in result assert 'chartreuse' in result
def test_deplicate(): """ It's an error to a keyword arguments """ # I am liking pytest more and more with pytest.raises(TypeError): result = colors('yellow', fore_color='purple') print(result)
def test_pos_and_keyword(): result = colors('yellow', 'gray', link_color='purple') # these aren't exhaustive by any means print(result) assert 'foreground: yellow' in result assert 'background: gray' in result assert 'link: purple' in result
def test_all_positional(): result = colors('red', 'blue', 'yellow', 'chartreuse') # this is not everything print(result) assert 'red' in result assert 'blue' in result assert 'chartreuse' in result
def test_duplicate(): """ It's an error to have a keyword argument that duplicates a positional one """ # this is the nifty pytest way to check for Exceptions with pytest.raises(TypeError): result = colors('yellow', fore_color='purple') print(result)
def test_manual_all_positional(): result = colors('red', 'blue', 'yellow', 'chartreuse') # these aren't exhaustive by any means # but mostly I want to make the code runs without error print(result) assert 'red' in result assert 'blue' in result assert 'chartreuse' in result
def test_call_tuple(): t = ('red', 'blue', 'yellow', 'chartreuse') result = colors(*t) # these aren't exhaustive by any means # but mostly I want to make the code runs without error print(result) assert 'red' in result assert 'blue' in result assert 'chartreuse' in result
def test_call_everything(): t = ('red', ) d = {'visited_color': 'cyan'} result = colors('blue', *t, link_color='orange', **d) print(result) assert 'foreground: blue' in result assert 'background: red' in result assert 'visited: cyan' in result assert 'link: orange' in result
def test_call_tuple_dict(): t = ('red', 'blue') d = {'visited_color': 'cyan', 'link_color': 'green'} result = colors(*t, **d) print(result) assert ' foreground: red' in result assert 'background: blue' in result assert 'visited: cyan' in result assert 'link: green' in result
def test_duplicate2(): """ It's an error to have a keyword argument that duplicates a positional one """ # this is a way to do it by hand: try: result = colors('yellow', fore_color='purple') print(result) assert False except TypeError as err: # you can also check if the error message is what you expect assert "multiple values for argument" in err.args[0]
def test_call_dict(): d = {'fore_color': 'red', 'visited_color': 'cyan', 'link_color': 'green', 'back_color': 'blue', } result = colors(**d) print(result) assert 'foreground: red' in result assert 'background: blue' in result assert 'visited: cyan' in result assert 'link: green' in result
def test_call_everything(): """ this one uses: - a positional argument - *tuple - a keyword argument - **dict """ t = ('red', ) # note the extra comma to amke it a tuple! d = {'visited_color': 'cyan'} result = colors('blue', *t, link_color='orange', **d) print(result) assert 'foreground: blue' in result assert 'background: red' in result assert 'visited: cyan' in result assert 'link: orange' in result
def test_pos_key_duplicate(): with pytest.raises(TypeError): result = colors('purple', fore_color="magenta") print(result)
def test_call_undefined_kwarg(): # should get an error passing in non-existand keyword with pytest.raises(TypeError): result = colors(weird_color='grey')
def test_one_keyword(): result = colors(link_color='purple') # these aren't exhaustive by any means # but mostly I want to make the code runs without error print(result) assert 'link: purple' in result
def test_call_undefined_kwarg(): with pytest.raises(TypeError): result = colors(wierd_color='grey')
def test_one_keyword(): result = colors(link_color='purple') # another attempt to test print(result) assert 'link: purple' in result