Separate code for testing if a file is Python into a new function

Also added a new unit test for the new function.