Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. (defmacro deffixture [fn-name docstring params &rest body]
  2. "Pytest parametrize reader."
  3. `(with-decorator
  4. (pytest.fixture :params ~params :scope "module")
  5. (defn ~fn-name [request]
  6. ~docstring
  7. (setv it request.param)
  8. ~@body)))
  9.  
  10. (defmacro with-fixture [fixture fn-name args &rest body]
  11. `(defn ~fn-name [~fixture]
  12. (setv ~args ~fixture)
  13. ~@body))
  14.  
  15. (defn assert~ [x y] (npt.assert-almost-equal x y))
  16.  
  17. (defmacro list-it [it &rest body]
  18. "Selectively transform components of a collection, mimicking xi macro.
  19.  
  20. Usage: (list-it [1 2] (+ x1 2) x2) -> [3, 2]"
  21. (setv flatbody (flatten body))
  22. `((fn [[~@(genexpr (HySymbol (+ "x" (str i)))
  23. [i (range 1
  24. (inc (max (+ (list-comp (int (cut a 1))
  25. [a flatbody]
  26. (and (symbol? a)
  27. (.startswith a 'x)
  28. (.isdigit (cut a 1))))
  29. [0]))))])
  30. ~@(if (in 'xi flatbody)
  31. '(&rest xi)
  32. '())]]
  33. [~@body]) ~it))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement