def test_tuple(self): # NOTE: this is really a border case and there is some cost/benefit adding it to as_list function # # +: it is good to think about "other options" # # -: "other options" are endless, and we can rather raise # error in bulk if we think that probability of bordercase # appeareing if low. as_list operates on written instruction, # so here we can assume one follows convention. appearance of # tuple is a rare hapening. # # In other words, it is a bit of 'made-up' situation and probably # in this case not worth the effort. Also had to change to another elif # to ensure the output is always a list. # # I'm writing this because cost/benefit tradeoff becomes more # important in rest of code, where some border cases are critical and some are not. # tup = tuple(["a", "b"]) assert as_list(tup) == ["a", "b"]
def test_argument_of_wrong_type(self): with pytest.raises(TypeError): as_list(1)
def test_single_arg(self): assert as_list("a") == ["a"] assert as_list(["a"]) == ["a"]
def test_list_arg(self): assert as_list(["a", "b"]) == ["a", "b"]
def test_tuple(self): tup = tuple(["a", "b"]) assert as_list(tup) == ["a", "b"]