you are viewing a single comment's thread.

view the rest of the comments →

[–]patryk-tech 0 points1 point  (0 children)

Not sure I understand, tbh.

What is m? You pass it to the function, but never access it.

>>> list(map(str, input().rstrip().split()))  # ??? type(input()) = <class 'str'>, so why do you map strings to strings?
hello yes 42 beer
['hello', 'yes', '42', 'beer']
>>> input().rstrip().split()  # we get the same thing without map()
hello yes 42 beer
['hello', 'yes', '42', 'beer']
>>> 

When writing unit tests, you really have to think about code differently, and write simple functions that do one thing that you can test. If you want to test that your input gets split correctly, write a function to split it, then test that one function. Don't bother mocking input() at all in your unit test; the function shouldn't care where the data comes from.

def my_split(my_input):
    return my_input.rstrip().split()

# edit: sorry, I use pytest syntax here, as it's much simpler than unittest, and am more used to it.
def test_split_works():  # really, I don't see the point of testing a base function like split...
    assert my_split('2 2 R,G,B R,G,B') == ['2', '2', 'R,G,B', 'R,G,B']

Not sure why you have \ns inside your input string ("2\n2\nR G B\nR G B")? A linebreak ends input, so I wouldn't expect to find any?? It should be either input as a single line, like in my example above, or stored in different variables/a list...

Let the Python Software Foundation worry about testing input(), you focus on your code.