Package: ply
Version: 3.4-3
Severity: normal
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu trusty ubuntu-patch

Dear Maintainer,

In Ubuntu, the attached patch was applied to achieve the following:

  * Enable test suite as part of package build:
    - d/rules: Execute lex and yacc tests for all python versions.
    - d/p/000*.patch: Cherry picked fixes from upstream VCS to resolve
      compatibility issues with Python >= 3.3.

Thanks for considering the patch.


-- System Information:
Debian Release: wheezy/sid
  APT prefers trusty-updates
  APT policy: (500, 'trusty-updates'), (500, 'trusty-security'), (500, 
'trusty'), (100, 'trusty-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.12.0-7-generic (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
--- debian/patches/0001-Fixed-yacc-tests-to-account-for-dict-hash-key-random.patch	1970-01-01 00:00:00 +0000
+++ debian/patches/0001-Fixed-yacc-tests-to-account-for-dict-hash-key-random.patch	2014-01-06 12:11:42 +0000
@@ -0,0 +1,98 @@
+From 02030ad24d923f16f401744a608573365b2e5542 Mon Sep 17 00:00:00 2001
+From: David Beazley <d...@dabeaz.com>
+Date: Tue, 21 May 2013 20:14:04 -0500
+Subject: [PATCH 1/3] Fixed yacc tests to account for dict hash key
+ randomization
+
+---
+ test/testlex.py    |  3 +--
+ test/testyacc.py   | 24 +++++++++++++++++++++---
+ test/yacc_prec1.py |  4 ++--
+ 3 files changed, 24 insertions(+), 7 deletions(-)
+
+diff --git a/test/testlex.py b/test/testlex.py
+index 1f7dd1b..e436781 100755
+--- a/test/testlex.py
++++ b/test/testlex.py
+@@ -34,7 +34,7 @@ def pymodule_out_exists(filename):
+ def pymodule_out_remove(filename):
+     os.remove(make_pymodule_path(filename))
+ 
+-def check_expected(result,expected):
++def check_expected(result, expected):
+     if sys.version_info[0] >= 3:
+         if isinstance(result,str):
+             result = result.encode('ascii')
+@@ -43,7 +43,6 @@ def check_expected(result,expected):
+     resultlines = result.splitlines()
+     expectedlines = expected.splitlines()
+ 
+-
+     if len(resultlines) != len(expectedlines):
+         return False
+ 
+diff --git a/test/testyacc.py b/test/testyacc.py
+index 2b06b44..4462201 100644
+--- a/test/testyacc.py
++++ b/test/testyacc.py
+@@ -34,7 +34,7 @@ def pymodule_out_exists(filename):
+ def pymodule_out_remove(filename):
+     os.remove(make_pymodule_path(filename))
+ 
+-
++# Old implementation (not safe for Python 3.3)
+ def check_expected(result,expected):
+     resultlines = []
+     for line in result.splitlines():
+@@ -52,6 +52,26 @@ def check_expected(result,expected):
+             return False
+     return True
+ 
++# Check the output to see if it contains all of a set of expected output lines.
++# This alternate implementation looks weird, but is needed to properly handle
++# some variations in error message order that occurs due to dict hash table
++# randomization that was introduced in Python 3.3
++def check_expected(result, expected):
++    resultlines = set()
++    for line in result.splitlines():
++        if line.startswith("WARNING: "):
++            line = line[9:]
++        elif line.startswith("ERROR: "):
++            line = line[7:]
++        resultlines.add(line)
++
++    # Selectively remove expected lines from the output
++    for eline in expected.splitlines():
++        resultlines = set(line for line in resultlines if not line.endswith(eline))
++
++    # Return True if no result lines remain
++    return not bool(resultlines)
++
+ def run_import(module):
+     code = "import "+module
+     exec(code)
+@@ -342,6 +362,4 @@ class YaccErrorWarningTests(unittest.TestCase):
+                                     "Precedence rule 'left' defined for unknown symbol '/'\n"
+                                     ))
+ 
+-
+-            
+ unittest.main()
+diff --git a/test/yacc_prec1.py b/test/yacc_prec1.py
+index 2ca6afc..99fcd90 100644
+--- a/test/yacc_prec1.py
++++ b/test/yacc_prec1.py
+@@ -12,8 +12,8 @@ from calclex import tokens
+ 
+ # Parsing rules
+ precedence = (
+-    ('left','+','-'),
+-    ('left','*','/'),
++    ('left', '+', '-'),
++    ('left', '*', '/'),
+     ('right','UMINUS'),
+     )
+ 
+-- 
+1.8.5.2
+

=== added file 'debian/patches/0002-More-test-fixes.patch'
--- debian/patches/0002-More-test-fixes.patch	1970-01-01 00:00:00 +0000
+++ debian/patches/0002-More-test-fixes.patch	2014-01-06 12:11:42 +0000
@@ -0,0 +1,55 @@
+From 55ff3fb3608d6112b315c85acd5b4348aaa32e12 Mon Sep 17 00:00:00 2001
+From: David Beazley <d...@dabeaz.com>
+Date: Tue, 21 May 2013 21:26:59 -0500
+Subject: [PATCH 2/3] More test fixes
+
+---
+ ply/yacc.py      | 8 ++++++--
+ test/testyacc.py | 5 +++++
+ 2 files changed, 11 insertions(+), 2 deletions(-)
+
+diff --git a/ply/yacc.py b/ply/yacc.py
+index e9f5c65..a29c645 100644
+--- a/ply/yacc.py
++++ b/ply/yacc.py
+@@ -195,8 +195,12 @@ class YaccProduction:
+         self.lexer = None
+         self.parser= None
+     def __getitem__(self,n):
+-        if n >= 0: return self.slice[n].value
+-        else: return self.stack[n].value
++        if isinstance(n, slice):
++            return [s.value for s in self.slice[n]]
++        elif n >= 0: 
++            return self.slice[n].value
++        else: 
++            return self.stack[n].value
+ 
+     def __setitem__(self,n,v):
+         self.slice[n].value = v
+diff --git a/test/testyacc.py b/test/testyacc.py
+index 4462201..86c991a 100644
+--- a/test/testyacc.py
++++ b/test/testyacc.py
+@@ -9,6 +9,7 @@ except ImportError:
+ import sys
+ import os
+ import warnings
++import re
+ 
+ sys.path.insert(0,"..")
+ sys.tracebacklimit = 0
+@@ -57,6 +58,10 @@ def check_expected(result,expected):
+ # some variations in error message order that occurs due to dict hash table
+ # randomization that was introduced in Python 3.3
+ def check_expected(result, expected):
++    # Normalize 'state n' text to account for randomization effects in Python 3.3
++    expected = re.sub(r' state \d+', 'state <n>', expected)
++    result = re.sub(r' state \d+', 'state <n>', result)
++
+     resultlines = set()
+     for line in result.splitlines():
+         if line.startswith("WARNING: "):
+-- 
+1.8.5.2
+

=== added file 'debian/patches/0003-Fixed-lexer-line-tracking.patch'
--- debian/patches/0003-Fixed-lexer-line-tracking.patch	1970-01-01 00:00:00 +0000
+++ debian/patches/0003-Fixed-lexer-line-tracking.patch	2014-01-06 12:11:42 +0000
@@ -0,0 +1,25 @@
+From 0c0b575b529d4fe6dc0be179e701a302f27bc127 Mon Sep 17 00:00:00 2001
+From: David Beazley <d...@dabeaz.com>
+Date: Thu, 26 Apr 2012 10:15:09 -0500
+Subject: [PATCH 3/3] Fixed lexer line tracking.
+
+---
+ test/calclex.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/test/calclex.py b/test/calclex.py
+index 67d245f..302f0b0 100644
+--- a/test/calclex.py
++++ b/test/calclex.py
+@@ -36,7 +36,7 @@ t_ignore = " \t"
+ 
+ def t_newline(t):
+     r'\n+'
+-    t.lineno += t.value.count("\n")
++    t.lexer.lineno += t.value.count("\n")
+     
+ def t_error(t):
+     print("Illegal character '%s'" % t.value[0])
+-- 
+1.8.5.2
+

=== modified file 'debian/patches/series'
--- debian/patches/series	2011-06-12 20:27:05 +0000
+++ debian/patches/series	2014-01-06 12:11:52 +0000
@@ -1,2 +1,5 @@
 01_fix-lex-tabversion.patch
 02_relax-lex-tabversion-check.patch
+0001-Fixed-yacc-tests-to-account-for-dict-hash-key-random.patch
+0002-More-test-fixes.patch
+0003-Fixed-lexer-line-tracking.patch

=== modified file 'debian/rules'
--- debian/rules	2011-07-04 17:37:14 +0000
+++ debian/rules	2014-01-06 11:28:08 +0000
@@ -10,6 +10,15 @@
 DEB_PYTHON_INSTALL_ARGS_ALL += --single-version-externally-managed \
 	--install-layout=deb
 
+PYVERSIONS := $(shell pyversions -s)
+PY3VERSIONS := $(shell py3versions -s)
+
+build:
+	for pyver in $(PYVERSIONS) $(PY3VERSIONS); do \
+		echo "Testing with $$pyver"; \
+		(cd test && $$pyver testlex.py && $$pyver testyacc.py && ./cleanup.sh;)\
+	done
+
 binary-install/python-ply::
 	pod2man debian/dh_python-ply > dh_python-ply.1
 	dh_installman -p python-ply dh_python-ply.1

Reply via email to