hy_odoo/hy_odoo/mtest.hy

36 lines
1.8 KiB
Hy

;; Copyright 2021-2022 Fabien Bourgeois <fabien@yaltik.com>
;;
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at https://mozilla.org/MPL/2.0/.
" Hy Odoo Tests Helpers and Macros "
(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))
(defmacro o-assert-not-equal [left right] `(.assertNotEqual self ~left ~right))
(defmacro o-assert-true [val] `(.assertTrue self ~val))
(defmacro o-assert-false [val] `(.assertFalse self ~val))
(defmacro o-assert-is [left right] `(.assertIs self ~left ~right))
(defmacro o-assert-is-not [left right] `(.assertIsNot self ~left ~right))
(defmacro o-assert-is-none [val] `(.assertIsNone self ~val))
(defmacro o-assert-is-not-none [val] `(.assertIsNotNone self ~val))
(defmacro o-assert-in [left right] `(.assertIn self ~left ~right))
(defmacro o-assert-not-in [left right] `(.assertNotIn self ~left ~right))
(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] `(.assertRaisesRegex self ~Error ~regexp))
(defmacro odo-assert-raises [Error body]
"Macro to test Error with self.assertRaises and do block"
`(with [err (.assertRaises self ~Error)] ~body))
(defmacro o-test [name body]
"Macro for unit test case"
(setv fn-name (% "test-%s" (str name))
humanized-name (.replace (str name) "-" " ")
descr (bytes (% "Test %s" humanized-name)))
`(defn ~(HySymbol fn-name) [self] ~descr ~body))