[pypy-commit] lang-js default: moved JsCode __eq__ and Opcode __eq__ to helper method in test_parser

stepahn noreply at buildbot.pypy.org
Fri May 13 13:45:17 CEST 2011


Author: Stephan <stephan at stzal.com>
Branch: 
Changeset: r45:042c5dd8756a
Date: 2011-05-12 16:23 +0200
http://bitbucket.org/pypy/lang-js/changeset/042c5dd8756a/

Log:	moved JsCode __eq__ and Opcode __eq__ to helper method in
	test_parser

diff --git a/js/jscode.py b/js/jscode.py
--- a/js/jscode.py
+++ b/js/jscode.py
@@ -103,11 +103,6 @@
             self.remove_labels()
         return JsFunction(name, params, self.opcodes)
 
-    def _freeze_(self):
-        if self.has_labels:
-            self.remove_labels()
-        return True
-
     def remove_labels(self):
         """ Basic optimization to remove all labels and change
         jumps to addresses. Necessary to run code at all
@@ -131,13 +126,6 @@
     def __repr__(self):
         return "\n".join([repr(i) for i in self.opcodes])
 
-    def __eq__(self, list_of_opcodes):
-        if not isinstance(list_of_opcodes, list):
-            return False
-        if len(list_of_opcodes) != len(self.opcodes):
-            return False
-        return all([i == j for i, j in zip(self.opcodes, list_of_opcodes)])
-
 class JsFunction(object):
     def __init__(self, name, params, code):
         self.name = name
@@ -210,9 +198,6 @@
         """
         raise NotImplementedError
 
-    def __eq__(self, other):
-        return repr(self) == other
-
     def __repr__(self):
         return self.__class__.__name__
 
diff --git a/js/test/test_parser.py b/js/test/test_parser.py
--- a/js/test/test_parser.py
+++ b/js/test/test_parser.py
@@ -289,9 +289,15 @@
 
     def check(self, source, expected):
         bytecode = self.compile(source)
-        assert bytecode == expected
+        assert_bytecode_list_eql(bytecode.opcodes, expected)
         return bytecode
 
+def assert_bytecode_list_eql(opcodes, list_of_opcodes):
+    assert isinstance(list_of_opcodes, list)
+    assert len(list_of_opcodes) == len(opcodes)
+    for i, j in zip(opcodes, list_of_opcodes):
+        assert repr(i) == j
+
 class TestToASTExpr(BaseTestToAST):
     def setup_class(cls):
         cls.parse = parse_func('expression')
@@ -382,7 +388,7 @@
     def check_remove_label(self, s, expected, expected_after_rl):
         bytecode = self.check(s, expected)
         bytecode.remove_labels()
-        assert bytecode == expected_after_rl
+        assert_bytecode_list_eql(bytecode.opcodes, expected_after_rl)
 
     def test_control_flow(self):
         self.check_remove_label('while (i>1) {x}',


More information about the pypy-commit mailing list