Raphael Collet (OpenERP) has proposed merging lp:~openerp-dev/openerp-web/trunk-datetests-rco into lp:openerp-web.
Requested reviews: Xavier (Open ERP) (xmo) For more details, see: https://code.launchpad.net/~openerp-dev/openerp-web/trunk-datetests-rco/+merge/139004 Fixes a js test failure that occurs once in a while. It happens when testing pyeval on datetimes. The result is compared to an independent call to new Date(), which may be different than the call used by pyeval. The difference we observed is only one second. The fix calls new Date() twice: once before the pyeval, and another after it. The result is checked to be between the expected results from both dates. -- https://code.launchpad.net/~openerp-dev/openerp-web/trunk-datetests-rco/+merge/139004 Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openerp-web/trunk-datetests-rco.
=== modified file 'addons/web/static/test/evals.js' --- addons/web/static/test/evals.js 2012-11-30 14:03:35 +0000 +++ addons/web/static/test/evals.js 2012-12-10 15:46:33 +0000 @@ -4,27 +4,37 @@ instance.session.uid = 42; } }, function (test) { + var makeTimeCheck = function (instance) { + var context = instance.web.pyeval.context(); + return function (expr, func, message) { + // evaluate expr between two calls to new Date(), and check that + // the result is between the transformed dates + var d0 = new Date; + var result = py.eval(expr, context); + var d1 = new Date; + ok(func(d0) <= result && result <= func(d1), message); + }; + }; test('strftime', function (instance) { - var d = new Date(); - var context = instance.web.pyeval.context(); - strictEqual( - py.eval("time.strftime('%Y')", context), - String(d.getFullYear())); - strictEqual( - py.eval("time.strftime('%Y')+'-01-30'", context), - String(d.getFullYear()) + '-01-30'); - strictEqual( - py.eval("time.strftime('%Y-%m-%d %H:%M:%S')", context), - _.str.sprintf('%04d-%02d-%02d %02d:%02d:%02d', + var check = makeTimeCheck(instance); + check("time.strftime('%Y')", function(d) { + return String(d.getFullYear()); + }); + check("time.strftime('%Y')+'-01-30'", function(d) { + return String(d.getFullYear()) + '-01-30'; + }); + check("time.strftime('%Y-%m-%d %H:%M:%S')", function(d) { + return _.str.sprintf('%04d-%02d-%02d %02d:%02d:%02d', d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate(), - d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds())); + d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds()); + }); }); test('context_today', function (instance) { - var d = new Date(); - var context = instance.web.pyeval.context(); - strictEqual( - py.eval("context_today().strftime('%Y-%m-%d')", context), - String(_.str.sprintf('%04d-%02d-%02d', d.getFullYear(), d.getMonth() + 1, d.getDate()))); + var check = makeTimeCheck(instance); + check("context_today().strftime('%Y-%m-%d')", function(d) { + return String(_.str.sprintf('%04d-%02d-%02d', + d.getFullYear(), d.getMonth() + 1, d.getDate())); + }); }); // Port from pypy/lib_pypy/test_datetime.py var makeEq = function (instance, c2) {
_______________________________________________ Mailing list: https://launchpad.net/~openerp-dev-gtk Post to : openerp-dev-gtk@lists.launchpad.net Unsubscribe : https://launchpad.net/~openerp-dev-gtk More help : https://help.launchpad.net/ListHelp