[FIX]In macros, from python2/3 form

This commit is contained in:
Fabien BOURGEOIS 2021-02-22 12:54:03 +01:00
parent cda0282a33
commit 2f5b50dcef
3 changed files with 21 additions and 3 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Fabien Bourgeois <fabien@yaltik.com>
# Copyright 2020-2021 Fabien Bourgeois <fabien@yaltik.com>
#
# 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 <http://www.gnu.org/licenses/>.
import hy
from . import macros,odoo, xml_base, test
import odoo, xml_base, test

View File

@ -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})

View File

@ -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"