Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defmacro deffixture [fn-name docstring params &rest body]
"Pytest parametrize reader."
(pytest.fixture :params ~params :scope "module")
(defn ~fn-name [request]
(setv it request.param)
(defmacro with-fixture [fixture fn-name args &rest body]
`(defn ~fn-name [~fixture]
(setv ~args ~fixture)
(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))))
~@(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