If that is just a test case and not a "real part of big system" - meaning that you just need to pass a certain input to your command line executable ones (e.g. run test) and you are using Unix, one convenient way of doing this is using pipes:
// read.py
val = raw_input()
print 'nice', val
then via console:
$ echo "hat" | python read.py
nice hat
on Windows syntax is little different - should be something like
dir> python.exe read.py < file.txt
One other hacky-simple way to achieve same thing is to replace sys.stdin with a custom stream object:
sys.stdin = StringIO.StringIO("line 1\nline 2\nline 3")
One should consider using @erip 's answer if that is something bigger than a automatisation routine or testing students' home assignments against fixed set of tests, though.
inputcan (and will) only be called once in the entire system, mocking isn't the right way to go.