class_docstr: Enable tests for a full test cases directory.
  
  This class load test from individual .py in a directory and expose
  them to the unittest framework. Methods are added to the class (not the
  instance object) because py.test will collect tests by introspection before
  eventually instantiating the class for each test.
  
  It is intended to be subclassed and then initialized using the static
  populate() method.
  
  A few class attributes defined the behavior:
  
  check_output -- Trigger code execution and match return value for Pythran
                  compiled code against pure python. If set to False, only
                  the compilation step is checked.
  files        -- list of files to load, if empty path is used (see below)
  path         -- path where every .py will be loaded
  interface    -- method returning the Pythran interface to use (dict)
class_docstr_tok: ["Enable","tests","for","a","full","test","cases","directory",".","This","class","load","test","from","individual",".py","in","a","directory","and","expose","them","to","the","unittest","framework",".","Methods","are","added","to","the","class","(","not","the","instance","object",")","because","py.test","will","collect","tests","by","introspection","before","eventually","instantiating","the","class","for","each","test",".","It","is","intended","to","be","subclassed","and","then","initialized","using","the","static","populate","(",")","method",".","A","few","class","attributes","defined","the","behavior",":","check_output","--","Trigger","code","execution","and","match","return","value","for","Pythran","compiled","code","against","pure","python",".","If","set","to","False",",","only","the","compilation","step","is","checked",".","files","--","list","of","files","to","load",",","if","empty","path","is","used","(","see","below",")","path","--","path","where","every",".py","will","be","loaded","interface","--","method","returning","the","Pythran","interface","to","use","(","dict",")"]
docstr: Add unittests methods to `target`.
  
  The python unittest framework detect method named test_* by
  introspection on the class before instantiation. Unfortunately to
  access the TestEnv instance from the method the Functor has to be
  initialized after `target` instantiation. Thus there is a two-stage
  initialization: first we populate the class with 'stub' functions, just
  to satisfy python unittest collect, and then at instantiation the stub
  are replace with the Functor properly initialized with a reference to
  "self".
docstr_tok: ["Add","unittests","methods","to","`","target","`",".","The","python","unittest","framework","detect","method","named","test_","*","by","introspection","on","the","class","before","instantiation",".","Unfortunately","to","access","the","TestEnv","instance","from","the","method","the","Functor","has","to","be","initialized","after","`","target","`","instantiation",".","Thus","there","is","a","two-stage","initialization",":","first","we","populate","the","class","with","'stub","'","functions",",","just","to","satisfy","python","unittest","collect",",","and","then","at","instantiation","the","stub","are","replace","with","the","Functor","properly","initialized","with","a","reference","to","''","self","''","."]
code: def populate(target, stub=True):
      """
      Add unittests methods to `target`.
  
      The python unittest framework detect method named test_* by
      introspection on the class before instantiation. Unfortunately to
      access the TestEnv instance from the method the Functor has to be
      initialized after `target` instantiation. Thus there is a two-stage
      initialization: first we populate the class with 'stub' functions, just
      to satisfy python unittest collect, and then at instantiation the stub
      are replace with the Functor properly initialized with a reference to
      "self".
      """
      if not target.files:
          # No explicit list of files, default to load the whole directory
          target.files = glob.glob(os.path.join(target.path, "*.py"))
  
      for filepath in target.files:
          # Module name is file name and external interface is default value
          name, _ = os.path.splitext(os.path.basename(filepath))
          specs = target.interface(name, filepath).functions
  
          runas_list = target.extract_runas(name, filepath)
          for n, runas in enumerate(runas_list):
              if runas:
                  # Remove the runas marker
                  runas = runas[runas.find(" ", 2) + 1 :]
                  suffix = "_run"
              else:
                  suffix = "_norun"
  
              if stub:
                  # First stage, we add dummy function.
                  def func():
                      """Useless function to populate TestCase."""
                      return
  
              else:
                  # Second stage, we change dummy function by real one.
                  with open(filepath) as fd:
                      func = TestFromDir.TestFunctor(
                          target,
                          name + suffix + str(n),
                          fd.read(),
                          os.path.dirname(filepath),
                          runas=runas,
                          **specs,
                      )
              setattr(target, "test_" + name + suffix + str(n), func)
  
imports: import importlib
  from numpy import float32, float64, complex128
  from numpy import intp, intc, number, bool_
  from numpy import ndarray, isnan, isinf, isneginf, complex128, complex64
  from textwrap import dedent
  from threading import Thread
  import copy
  import math
  import glob
  import numpy.testing
  import os
  import numbers
  import sys
  import unittest
  from functools import reduce
  from operator import add
  import logging
  from pythran import compile_pythrancode, spec_parser, load_specfile, frontend
  from pythran.backend import Python
  from pythran.middlend import refine
  from pythran.passmanager import PassManager
  from pythran.toolchain import _parse_optimization
  from pythran.spec import Spec
label_desc: Use image node_id 4 for calling the TestFromDir obj's underlying member method code with example usage: obj.populate(target, stub) without return types