diff options
Diffstat (limited to 'test/test_execfile.py')
-rw-r--r-- | test/test_execfile.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/test/test_execfile.py b/test/test_execfile.py index 5e9f4fd5..2f28a069 100644 --- a/test/test_execfile.py +++ b/test/test_execfile.py @@ -17,7 +17,7 @@ class RunTest(CoverageTest): tryfile = os.path.join(here, "try_execfile.py") run_python_file(tryfile, [tryfile, "arg1", "arg2"]) mod_globs = eval(self.stdout()) - + # The file should think it is __main__ self.assertEqual(mod_globs['__name__'], "__main__") @@ -30,10 +30,10 @@ class RunTest(CoverageTest): "Test file for run_python_file.") self.assertEqual(mod_globs['DATA'], "xyzzy") self.assertEqual(mod_globs['FN_VAL'], "my_fn('fooey')") - + # It must be self-importable as __main__. self.assertEqual(mod_globs['__main__.DATA'], "xyzzy") - + # Argv should have the proper values. self.assertEqual(mod_globs['argv'], [tryfile, "arg1", "arg2"]) @@ -60,5 +60,17 @@ class RunTest(CoverageTest): run_python_file('nl.py', ['nl.py']) self.assertEqual(self.stdout(), "Hello, world!\n"*3) + def test_missing_final_newline(self): + # Make sure we can deal with a Python file with no final newline. + self.make_file("abrupt.py", """\ + if 1: + a = 1 + print("a is %r" % a) + #""") + abrupt = open("abrupt.py").read() + self.assertEqual(abrupt[-1], '#') + run_python_file("abrupt.py", ["abrupt.py"]) + self.assertEqual(self.stdout(), "a is 1\n") + def test_no_such_file(self): self.assertRaises(NoSource, run_python_file, "xyzzy.py", []) |