(defmacro deffixture [fn-name docstring params &rest body] | |
"Pytest parametrize reader." | |
`(with-decorator | |
(pytest.fixture :params ~params :scope "module") | |
(defn ~fn-name [request] | |
~docstring | |
(setv it request.param) | |
~@body))) | |
(defmacro with-fixture [fixture fn-name args &rest body] | |
`(defn ~fn-name [~fixture] | |
(setv ~args ~fixture) | |
~@body)) | |
(defn assert~ [x y] (npt.assert-almost-equal x y)) | |
(defmacro list-it [it &rest body] | |
"Selectively transform components of a collection, mimicking xi macro. | |
Usage: (list-it [1 2] (+ x1 2) x2) -> [3, 2]" | |
(setv flatbody (flatten body)) | |
`((fn [[~@(genexpr (HySymbol (+ "x" (str i))) | |
[i (range 1 | |
(inc (max (+ (list-comp (int (cut a 1)) | |
[a flatbody] | |
(and (symbol? a) | |
(.startswith a 'x) | |
(.isdigit (cut a 1)))) | |
[0]))))]) | |
~@(if (in 'xi flatbody) | |
'(&rest xi) | |
'())]] | |
[~@body]) ~it)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment