Commits

masklinn  committed 32ed378

Test PY_call

  • Participants
  • Parent commits 49911fa

Comments (0)

Files changed (2)

+var py = require('../lib/py.js'),
+    expect = require('expect.js');
+
+var ev = function (str, context) {
+    return py.evaluate(py.parse(py.tokenize(str)), context);
+};
+
+describe('PY_call', function () {
+    it('should call a function', function () {
+        var called = false;
+        var f = py.PY_def.fromJSON(function () {
+            called = true;
+        });
+        py.PY_call(f);
+        expect(called).to.be(true);
+    });
+    it('should instantiate types', function () {
+        var s = py.PY_call(py.str);
+        expect(s.__class__).to.be(py.str);
+        expect(s.toJSON()).to.be('');
+    });
+    it('should __call__ objects', function () {
+        var called = false;
+        var c = py.PY_call(py.type('c', null, {
+            __call__: function () {
+                called = true;
+            }
+        }));
+        expect(called).to.be(false);
+        py.PY_call(c);
+        expect(called).to.be(true);
+    });
+});

File test/helpers/call.js

-var py = require('../../lib/py.js'),
-    expect = require('expect.js');
-
-var ev = function (str, context) {
-    return py.evaluate(py.parse(py.tokenize(str)), context);
-};