Skip to content

Instantly share code, notes, and snippets.

@jerith
Created February 10, 2013 09:25
Show Gist options
  • Select an option

  • Save jerith/4748958 to your computer and use it in GitHub Desktop.

Select an option

Save jerith/4748958 to your computer and use it in GitHub Desktop.
diff --git a/tests/test_interpreter.py b/tests/test_interpreter.py
index 05536b4..e87da42 100644
--- a/tests/test_interpreter.py
+++ b/tests/test_interpreter.py
@@ -225,7 +225,7 @@ class TestInterpreter(BaseTopazTest):
end
""")
w_cls = space.w_object.constants_w["X"]
- assert w_cls.methods_w.viewkeys() == {"m", "f"}
+ assert set(w_cls.methods_w.keys()) == set(["m", "f"])
w_res = space.execute("""
class Z < X
@@ -254,7 +254,7 @@ class TestInterpreter(BaseTopazTest):
end
""")
w_cls = space.w_object.constants_w["X"]
- assert w_cls.methods_w.viewkeys() == {"m", "f"}
+ assert set(w_cls.methods_w.keys()) == set(["m", "f"])
def test_reopen_non_class(self, space):
space.execute("""
diff --git a/tests/test_main.py b/tests/test_main.py
index 326fda8..4f29eda 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -25,7 +25,8 @@ class TestMain(object):
f = self.run(space, tmpdir, src, status=1)
out, err = capfd.readouterr()
assert not out
- actual_lines = err.splitlines()
+ actual_lines = [line for line in err.splitlines()
+ if '.message' not in line]
expected_lines = []
for line in expected:
expected_lines.append(line.format(f))
@@ -54,7 +55,7 @@ class TestMain(object):
def test___FILE__(self, space, tmpdir, capfd):
f = self.run(space, tmpdir, "puts __FILE__")
out, err = capfd.readouterr()
- assert out == "{}\n".format(f)
+ assert out == "{0}\n".format(f)
def test_verbose(self, space, tmpdir, capfd):
self.run(space, tmpdir, "puts 5", ruby_args=["-v"])
@@ -93,25 +94,25 @@ class TestMain(object):
f { 1 / 0}
""", [
- "{}:6:in `/': divided by 0 (ZeroDivisionError)",
- "\tfrom {}:6:in `block in <main>'",
- "\tfrom {}:3:in `f'",
- "\tfrom {}:6:in `<main>'",
+ "{0}:6:in `/': divided by 0 (ZeroDivisionError)",
+ "\tfrom {0}:6:in `block in <main>'",
+ "\tfrom {0}:3:in `f'",
+ "\tfrom {0}:6:in `<main>'",
])
def test_syntax_error(self, space, tmpdir, capfd):
self.assert_traceback(space, tmpdir, capfd, """
while do
""", [
- "{}: line 2 (SyntaxError)",
+ "{0}: line 2 (SyntaxError)",
])
def test_traceback_load_const(self, space, tmpdir, capfd):
self.assert_traceback(space, tmpdir, capfd, """
UnknownConst
""", [
- "{}:2:in `const_missing': uninitialized constant UnknownConst (NameError)",
- "\tfrom {}:2:in `<main>'",
+ "{0}:2:in `const_missing': uninitialized constant UnknownConst (NameError)",
+ "\tfrom {0}:2:in `<main>'",
])
def test_traceback_class(self, space, tmpdir, capfd):
@@ -120,9 +121,9 @@ class TestMain(object):
1 / 0
end
""", [
- "{}:3:in `/': divided by 0 (ZeroDivisionError)",
- "\tfrom {}:3:in `<class:X>'",
- "\tfrom {}:1:in `<main>'",
+ "{0}:3:in `/': divided by 0 (ZeroDivisionError)",
+ "\tfrom {0}:3:in `<class:X>'",
+ "\tfrom {0}:1:in `<main>'",
])
@pytest.mark.xfail
@@ -132,9 +133,9 @@ class TestMain(object):
end
f
""", [
- "{}:2:in `/': divided by 0 (ZeroDivisionError)",
- "\tfrom {}:2:in `f'",
- "\tfrom {}:4:in `<main>'",
+ "{0}:2:in `/': divided by 0 (ZeroDivisionError)",
+ "\tfrom {0}:2:in `f'",
+ "\tfrom {0}:4:in `<main>'",
])
def test_ruby_engine(self, space, tmpdir, capfd):
@@ -168,10 +169,10 @@ class TestMain(object):
"1",
]
assert err.splitlines() == [
- "{}:3:in `/': divided by 0 (ZeroDivisionError)".format(f),
- "\tfrom {}:3:in `block in <main>'".format(f),
- "{}:5:in `/': divided by 0 (ZeroDivisionError)".format(f),
- "\tfrom {}:5:in `<main>'".format(f),
+ "{0}:3:in `/': divided by 0 (ZeroDivisionError)".format(f),
+ "\tfrom {0}:3:in `block in <main>'".format(f),
+ "{0}:5:in `/': divided by 0 (ZeroDivisionError)".format(f),
+ "\tfrom {0}:5:in `<main>'".format(f),
]
def test_program_global(self, space, tmpdir, capfd):
@@ -180,7 +181,7 @@ class TestMain(object):
assert out1 == "-e\n"
f = self.run(space, tmpdir, "puts $0")
out2, err2 = capfd.readouterr()
- assert out2 == "{}\n".format(f)
+ assert out2 == "{0}\n".format(f)
def test_non_existent_file(self, space, tmpdir, capfd):
self.run(space, tmpdir, None, ruby_args=[str(tmpdir.join("t.rb"))], status=1)
diff --git a/topaz/foo.py b/topaz/foo.py
new file mode 100644
index 0000000..e3c23cf
--- /dev/null
+++ b/topaz/foo.py
@@ -0,0 +1,3 @@
+from ordereddict import OrderedDict
+
+__all__ = ['OrderedDict']
diff --git a/topaz/gateway.py b/topaz/gateway.py
index 71f0b85..1330ed6 100644
--- a/topaz/gateway.py
+++ b/topaz/gateway.py
@@ -34,15 +34,15 @@ class WrapperGenerator(object):
for i, argname in enumerate(args):
if argname in self.argspec or argname.startswith("w_"):
if argname.startswith("w_"):
- coerce_code = "args_w[{:d}]".format(self.arg_count)
+ coerce_code = "args_w[{0:d}]".format(self.arg_count)
else:
spec = self.argspec[argname]
- coerce_code = "Coerce.{}(space, args_w[{:d}])".format(spec, self.arg_count)
- lines.append(" if len(args_w) > {}:".format(self.arg_count))
- lines.append(" args += ({},)".format(coerce_code))
+ coerce_code = "Coerce.{0}(space, args_w[{1:d}])".format(spec, self.arg_count)
+ lines.append(" if len(args_w) > {0}:".format(self.arg_count))
+ lines.append(" args += ({0},)".format(coerce_code))
lines.append(" else:")
if default_start is not None and i >= default_start:
- lines.append(" args += (defaults[{:d}],)".format(i - default_start))
+ lines.append(" args += (defaults[{0:d}],)".format(i - default_start))
else:
lines.append(" raise SystemError('bad arg count')")
self.arg_count += 1
diff --git a/topaz/module.py b/topaz/module.py
index a892900..1b296b6 100644
--- a/topaz/module.py
+++ b/topaz/module.py
@@ -45,7 +45,10 @@ class ClassDef(object):
def singleton_method(self, name, **argspec):
def adder(func):
if isinstance(func, staticmethod):
- func = func.__func__
+ try:
+ func = func.__func__
+ except AttributeError:
+ func = func.__get__(1)
self.singleton_methods[name] = (func, argspec)
return staticmethod(func)
return adder
diff --git a/topaz/utils/ordereddict.py b/topaz/utils/ordereddict.py
index 2854178..8492c11 100644
--- a/topaz/utils/ordereddict.py
+++ b/topaz/utils/ordereddict.py
@@ -1,5 +1,8 @@
import operator
-from collections import OrderedDict as PyOrderedDict
+try:
+ from collections import OrderedDict as PyOrderedDict
+except ImportError:
+ from topaz.foo import OrderedDict as PyOrderedDict
from rpython.annotator import model
from rpython.annotator.bookkeeper import getbookkeeper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment