From 2f5b50dcefb054d1072c6a4b9436eeadd6fcdc88 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Mon, 22 Feb 2021 12:54:03 +0100 Subject: [PATCH] [FIX]In macros, from python2/3 form --- hy_odoo/__init__.py | 4 ++-- hy_odoo/macros/general.hy | 13 +++++++++++++ hy_odoo/macros/test.hy | 7 ++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/hy_odoo/__init__.py b/hy_odoo/__init__.py index 4ad51cc..f2426ae 100644 --- a/hy_odoo/__init__.py +++ b/hy_odoo/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Fabien Bourgeois +# Copyright 2020-2021 Fabien Bourgeois # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -16,4 +16,4 @@ # along with this program. If not, see . import hy -from . import macros,odoo, xml_base, test +import odoo, xml_base, test diff --git a/hy_odoo/macros/general.hy b/hy_odoo/macros/general.hy index 9916485..f26a543 100644 --- a/hy_odoo/macros/general.hy +++ b/hy_odoo/macros/general.hy @@ -28,3 +28,16 @@ (defmacro ustr-cast [s] "If python2, return unicode casting, else str casting" (if-python2 `(unicode ~s) `(str ~s))) + +(defmacro hydict [dic] + "Generate dict with mangled keys, from HyDict list" + (setv mangled-dic + (list + (map + (fn [pair] + (if (even? (nth pair 0)) + (mangle (nth pair 1)) + (nth pair 1))) + (enumerate dic)))) + `{~@mangled-dic}) + diff --git a/hy_odoo/macros/test.hy b/hy_odoo/macros/test.hy index 24fc703..9396b28 100644 --- a/hy_odoo/macros/test.hy +++ b/hy_odoo/macros/test.hy @@ -17,6 +17,8 @@ " Hy Odoo Tests Helpers and Macros " +(require [hy-odoo.macros.general [if-python2]]) + (defmacro o-assert-equal [left right] `(.assertEqual self ~left ~right)) (defmacro o-assert-list-equal [left right] `(.assertListEqual self ~left ~right)) (defmacro o-assert-dict-equal [left right] `(.assertDictEqual self ~left ~right)) @@ -32,7 +34,10 @@ (defmacro o-assert-is-instance [left right] `(.assertIsInstance self ~left ~right)) (defmacro o-assert-not-is-instance [left right] `(.assertNotIsInstance self ~left ~right)) (defmacro o-assert-raises [Error] `(.assertRaises self ~Error)) -(defmacro o-assert-raises-regex [Error regexp] `(.assertRaisesRegexp self ~Error ~regexp)) +(defmacro o-assert-raises-regex [Error regexp] + (if-python2 + `(.assertRaisesRegexp self ~Error ~regexp) + `(.assertRaisesRegex self ~Error ~regexp))) (defmacro odo-assert-raises [Error body] "Macro to test Error with self.assertRaises and do block"