Skip to content
Snippets Groups Projects
testing.nix 740 B
Newer Older
{

  /* Returns a string that runs tests from the Python code at the given path.

     The Python code is loaded using *execfile* and the *test* global it
     defines is called with the given keyword arguments.

     Type: makeTestScript :: Path -> AttrSet -> String

     Example:
       testScript = (makeTestScript ./test_foo.py { x = "y"; });
  */
  makeTestScript = { testpath, kwargs ? {} }:
    ''
    # The driver runs pyflakes on this script before letting it
    # run... Convince pyflakes that there is a `test` name.
    test = None
    with open("${testpath}") as testfile:
        exec(testfile.read(), globals())
    # For simple types, JSON is compatible with Python syntax!
    test(**${builtins.toJSON kwargs})
    '';
}