David Beazley avatar David Beazley committed cf4902d

Fixed for Python 3.2

Comments (0)

Files changed (2)

     import io as StringIO
 
 import sys
+import os
+import imp
+import warnings
+
 sys.path.insert(0,"..")
 sys.tracebacklimit = 0
 
 import ply.lex
 
+def make_pymodule_path(filename):
+    path = os.path.dirname(filename)
+    file = os.path.basename(filename)
+    mod, ext = os.path.splitext(file)
+
+    if sys.hexversion >= 0x3020000:
+        modname = mod+"."+imp.get_tag()+ext
+        fullpath = os.path.join(path,'__pycache__',modname)
+    else:
+        fullpath = filename
+    return fullpath
+
+def pymodule_out_exists(filename):
+    return os.path.exists(make_pymodule_path(filename))
+
+def pymodule_out_remove(filename):
+    os.remove(make_pymodule_path(filename))
+
 def check_expected(result,expected):
     if sys.version_info[0] >= 3:
         if isinstance(result,str):
     def setUp(self):
         sys.stderr = StringIO.StringIO()
         sys.stdout = StringIO.StringIO()
+        if sys.hexversion >= 0x3020000:
+            warnings.filterwarnings('ignore',category=ResourceWarning)
+
     def tearDown(self):
         sys.stderr = sys.__stderr__
         sys.stdout = sys.__stdout__
                                     "(NUMBER,3,1,0)\n"
                                     "(PLUS,'+',1,1)\n"
                                     "(NUMBER,4,1,2)\n"))
-        self.assert_(os.path.exists("lextab.pyo"))
+        self.assert_(pymodule_out_exists("lextab.pyo"))
 
-        os.remove("lextab.pyo")
+        pymodule_out_remove("lextab.pyo")
         p = subprocess.Popen([sys.executable,'-OO','lex_optimize.py'],
                              stdout=subprocess.PIPE)
         result = p.stdout.read()
                                     "(NUMBER,3,1,0)\n"
                                     "(PLUS,'+',1,1)\n"
                                     "(NUMBER,4,1,2)\n"))
-        self.assert_(os.path.exists("lextab.pyo"))
+        self.assert_(pymodule_out_exists("lextab.pyo"))
         try:
             os.remove("lextab.py")
         except OSError:
             pass
         try:
-            os.remove("lextab.pyc")
+            pymodule_out_remove("lextab.pyc")
         except OSError:
             pass
         try:
-            os.remove("lextab.pyo")
+            pymodule_out_remove("lextab.pyo")
         except OSError:
             pass
 
                                     "(NUMBER,3,1,0)\n"
                                     "(PLUS,'+',1,1)\n"
                                     "(NUMBER,4,1,2)\n"))
-        self.assert_(os.path.exists("opt2tab.pyo"))
-        os.remove("opt2tab.pyo")
+        self.assert_(pymodule_out_exists("opt2tab.pyo"))
+        pymodule_out_remove("opt2tab.pyo")
         p = subprocess.Popen([sys.executable,'-OO','lex_optimize2.py'],
                              stdout=subprocess.PIPE)
         result = p.stdout.read()
                                     "(NUMBER,3,1,0)\n"
                                     "(PLUS,'+',1,1)\n"
                                     "(NUMBER,4,1,2)\n"))
-        self.assert_(os.path.exists("opt2tab.pyo"))
+        self.assert_(pymodule_out_exists("opt2tab.pyo"))
         try:
             os.remove("opt2tab.py")
         except OSError:
             pass
         try:
-            os.remove("opt2tab.pyc")
+            pymodule_out_remove("opt2tab.pyc")
         except OSError:
             pass
         try:
-            os.remove("opt2tab.pyo")
+            pymodule_out_remove("opt2tab.pyo")
         except OSError:
             pass
 
                                     "(NUMBER,3,1,0)\n"
                                     "(PLUS,'+',1,1)\n"
                                     "(NUMBER,4,1,2)\n"))
-        self.assert_(os.path.exists("lexdir/sub/calctab.pyo"))
-        os.remove("lexdir/sub/calctab.pyo")
+        self.assert_(pymodule_out_exists("lexdir/sub/calctab.pyo"))
+        pymodule_out_remove("lexdir/sub/calctab.pyo")
         p = subprocess.Popen([sys.executable,'-OO','lex_optimize3.py'],
                              stdout=subprocess.PIPE)
         result = p.stdout.read()
                                     "(NUMBER,3,1,0)\n"
                                     "(PLUS,'+',1,1)\n"
                                     "(NUMBER,4,1,2)\n"))
-        self.assert_(os.path.exists("lexdir/sub/calctab.pyo"))
+        self.assert_(pymodule_out_exists("lexdir/sub/calctab.pyo"))
         try:
             shutil.rmtree("lexdir")
         except OSError:
                                     "(NUMBER,3,1,0)\n"
                                     "(+,'+',1,1)\n"
                                     "(NUMBER,4,1,2)\n"))
-        self.assert_(os.path.exists("aliastab.pyo"))
-        os.remove("aliastab.pyo")
+        self.assert_(pymodule_out_exists("aliastab.pyo"))
+        pymodule_out_remove("aliastab.pyo")
         p = subprocess.Popen([sys.executable,'-OO','lex_opt_alias.py'],
                              stdout=subprocess.PIPE)
         result = p.stdout.read()
                                     "(NUMBER,3,1,0)\n"
                                     "(+,'+',1,1)\n"
                                     "(NUMBER,4,1,2)\n"))
-        self.assert_(os.path.exists("aliastab.pyo"))
+        self.assert_(pymodule_out_exists("aliastab.pyo"))
         try:
             os.remove("aliastab.py")
         except OSError:
             pass
         try:
-            os.remove("aliastab.pyc")
+            pymodule_out_remove("aliastab.pyc")
         except OSError:
             pass
         try:
-            os.remove("aliastab.pyo")
+            pymodule_out_remove("aliastab.pyo")
         except OSError:
             pass
 
                                     "(TOK999,'TOK999:',1,47)\n"
                                     ))
 
-        self.assert_(os.path.exists("manytab.pyo"))
-        os.remove("manytab.pyo")
+        self.assert_(pymodule_out_exists("manytab.pyo"))
+        pymodule_out_remove("manytab.pyo")
         try:
             os.remove("manytab.py")
         except OSError:
 
 import sys
 import os
+import warnings
 
 sys.path.insert(0,"..")
 sys.tracebacklimit = 0
 
 import ply.yacc
+import imp
+
+def make_pymodule_path(filename):
+    path = os.path.dirname(filename)
+    file = os.path.basename(filename)
+    mod, ext = os.path.splitext(file)
+
+    if sys.hexversion >= 0x3020000:
+        modname = mod+"."+imp.get_tag()+ext
+        fullpath = os.path.join(path,'__pycache__',modname)
+    else:
+        fullpath = filename
+    return fullpath
+
+def pymodule_out_exists(filename):
+    return os.path.exists(make_pymodule_path(filename))
+
+def pymodule_out_remove(filename):
+    os.remove(make_pymodule_path(filename))
+
 
 def check_expected(result,expected):
     resultlines = []
         sys.stdout = StringIO.StringIO()
         try:
             os.remove("parsetab.py")
-            os.remove("parsetab.pyc")
+            pymodule_out_remove("parsetab.pyc")
         except OSError:
             pass
         
+        if sys.hexversion >= 0x3020000:
+            warnings.filterwarnings('ignore',category=ResourceWarning)
+
     def tearDown(self):
         sys.stderr = sys.__stderr__
         sys.stdout = sys.__stdout__
     def test_yacc_uprec(self):
         self.assertRaises(ply.yacc.YaccError,run_import,"yacc_uprec")
         result = sys.stderr.getvalue()
-        print repr(result)
         self.assert_(check_expected(result,
                                     "yacc_uprec.py:37: Nothing known about the precedence of 'UMINUS'\n"
                                     ))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.