def shsplit(*args): """ Older python (2.6) requires bytes into shlex.split so enforce that """ if sys.version_info < (2,7): args = [pyprepro._touni(a).encode('utf8') for a in args] return shlex.split(*args)
def test_name(self): """ Test that it fails when presented with an undefined variable """ input="""\ {param1 = 10} {param2} """ if sys.version_info < (2,7): print('Skipping error_capture tests for 2.6',file=sys.stderr) return with open('_testin.inp','w') as F: F.write(input) with CLI_Error() as E: pyprepro.pyprepro('_testin.inp') # make sure it failed self.assert_(E.exit_code != 0) stderr = pyprepro._touni(E.stderr) gold = ''' Error occurred Exception: NameError Message: name 'param2' is not defined ''' self.assert_(compare_lines(stderr,gold)) # Also test when it is called with CLI_Error() as E2: pyprepro.pyprepro("%include('_testin.inp')") self.assert_(E.exit_code != 0) self.assert_(compare_lines(pyprepro._touni(E2.stderr),gold)) os.remove('_testin.inp') # Via module self.assertRaises(NameError,pyprepro.pyprepro,input) # Should fail
def test_syntax(self): input = """\ This should throw a SyntaxError on line 4 Error Statement: {'{0}'.format('hi'} """ if sys.version_info < (2, 7): print('Skipping error_capture tests for 2.6', file=sys.stderr) return with open('_testin.inp', 'w') as F: F.write(input) with CLI_Error() as E: pyprepro.pyprepro('_testin.inp') # make sure it failed self.assert_(E.exit_code != 0) stderr = pyprepro._touni(E.stderr) gold = ''' Error occurred Exception: SyntaxError Filename: {} Approximate Line Number: 4 Message: {} '''.format(os.path.abspath('_testin.inp'), 'invalid syntax' if not PY3 else 'unexpected EOF while parsing') self.assert_(compare_lines(stderr, gold)) # Also test when it is called with CLI_Error() as E2: pyprepro.pyprepro("%include('_testin.inp')") self.assert_(E.exit_code != 0) self.assert_(compare_lines(pyprepro._touni(E2.stderr), gold)) os.remove('_testin.inp') # Via module self.assertRaises(SyntaxError, pyprepro.pyprepro, input) # Should fail