def test_manual_pos_and_keyword(): result = colors_manual('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_manual_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_manual('yellow', fore_color='purple') print(result)
def test_manual_call_tuple(): t = ('red', 'blue', 'yellow', 'chartreuse') result = colors_manual(*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_manual_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_manual('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_manual_call_tuple_dict(): t = ('red', 'blue') d = {'visited_color': 'cyan', 'link_color': 'green', } result = colors_manual(*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_manual_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_manual('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_manual_call_undefined_kwarg(): # should get an error passing in non-existand keyword with pytest.raises(TypeError): result = colors_manual(weird_color='grey')
def test_manual_one_keyword(): result = colors_manual(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