Exemplo n.º 1
0
def loadSource(fileName):
    baseName = os.path.basename(fileName)
    moduleName = os.path.splitext(baseName)[0]

    # for users wanted to run unittests under django
    #because of django took advantage of module name
    settings_file = os.getenv('DJANGO_SETTINGS_MODULE')
    if settings_file and moduleName == "models":
        baseName = os.path.realpath(fileName)
        moduleName = ".".join((baseName.split(os.sep)[-2], "models"))

    if moduleName in modules and len(
            sys.argv[1:-1]
    ) == 1:  # add unique number to prevent name collisions
        cnt = 2
        prefix = moduleName
        while getModuleName(prefix, cnt) in modules:
            cnt += 1
        moduleName = getModuleName(prefix, cnt)
    debug("/ Loading " + fileName + " as " + moduleName)
    if os.path.isdir(fileName):
        fileName = fileName + os.path.sep
    module = imp.load_source(moduleName, fileName)
    modules[moduleName] = module
    return module
Exemplo n.º 2
0
def loadSource(fileName):
    """
  loads source from fileName,
  we can't use tat function from utrunner, because of we
  store modules in global variable.
  """
    baseName = os.path.basename(fileName)
    moduleName = os.path.splitext(baseName)[0]

    # for users wanted to run simple doctests under django
    #because of django took advantage of module name
    settings_file = os.getenv('DJANGO_SETTINGS_MODULE')
    if settings_file and moduleName == "models":
        baseName = os.path.realpath(fileName)
        moduleName = ".".join((baseName.split(os.sep)[-2], "models"))

    if moduleName in modules:  # add unique number to prevent name collisions
        cnt = 2
        prefix = moduleName
        while getModuleName(prefix, cnt) in modules:
            cnt += 1
        moduleName = getModuleName(prefix, cnt)
    debug("/ Loading " + fileName + " as " + moduleName)
    module = _load_file(moduleName, fileName)
    modules[moduleName] = module
    return module
Exemplo n.º 3
0
def loadSource(fileName):
  """
  loads source from fileName,
  we can't use tat function from utrunner, because of we
  store modules in global variable.
  """
  baseName = os.path.basename(fileName)
  moduleName = os.path.splitext(baseName)[0]

  # for users wanted to run simple doctests under django
  #because of django took advantage of module name
  settings_file = os.getenv('DJANGO_SETTINGS_MODULE')
  if settings_file and moduleName=="models":
    baseName = os.path.realpath(fileName)
    moduleName = ".".join((baseName.split(os.sep)[-2], "models"))

  if moduleName in modules: # add unique number to prevent name collisions
    cnt = 2
    prefix = moduleName
    while getModuleName(prefix, cnt) in modules:
      cnt += 1
    moduleName = getModuleName(prefix, cnt)
  debug("/ Loading " + fileName + " as " + moduleName)
  module = imp.load_source(moduleName, fileName)
  modules[moduleName] = module
  return module
Exemplo n.º 4
0
def process_args():
  tests = []

  opts = None
  if sys.argv[-1].startswith("-"):
    test_names = sys.argv[1:-1]
    opts = sys.argv[-1]
  else:
    test_names = sys.argv[1:]

  for arg in test_names:
    arg = arg.strip()
    if len(arg) == 0:
      return

    a = arg.split("::")
    if len(a) == 1:
      # From module or folder
      a_splitted = a[0].split(";")
      if len(a_splitted) != 1:
        # means we have pattern to match against
        if a_splitted[0].endswith("/"):
          debug("/ from folder " + a_splitted[0] + ". Use pattern: " + a_splitted[1])
          tests.append(a_splitted[0])
      else:
        if a[0].endswith("/"):
          debug("/ from folder " + a[0])
          tests.append(a[0])
        else:
          debug("/ from module " + a[0])
          tests.append(a[0])

    elif len(a) == 2:
      # From testcase
      debug("/ from testcase " + a[1] + " in " + a[0])
      tests.append(a[0] + ":" + a[1])
    else:
      # From method in class or from function
      debug("/ from method " + a[2] + " in testcase " +  a[1] + " in " + a[0])
      if a[1] == "":
        # test function, not method
        tests.append(a[0] + ":" + a[2])
      else:
        tests.append(a[0] + ":" + a[1] + "." + a[2])

  argv = ['nosetests']

  argv.extend(tests)


  if opts:
    options = shlex.split(opts)
    argv.extend(options)

  manager = DefaultPluginManager()
  manager.addPlugin(teamcity_plugin)
  config = MyConfig(plugins=manager)
  config.configure(argv)

  TestProgram(argv=argv, config=config, exit=False)
Exemplo n.º 5
0
def process_args():
  tests = []

  opts = None
  if sys.argv[-1].startswith("-"):
    test_names = sys.argv[1:-1]
    opts = sys.argv[-1]
  else:
    test_names = sys.argv[1:]

  for arg in test_names:
    arg = arg.strip()
    if len(arg) == 0:
      return

    a = arg.split("::")
    if len(a) == 1:
      # From module or folder
      a_splitted = a[0].split(";")
      if len(a_splitted) != 1:
        # means we have pattern to match against
        if a_splitted[0].endswith("/"):
          debug("/ from folder " + a_splitted[0] + ". Use pattern: " + a_splitted[1])
          tests.append(a_splitted[0])
      else:
        if a[0].endswith("/"):
          debug("/ from folder " + a[0])
          tests.append(a[0])
        else:
          debug("/ from module " + a[0])
          tests.append(a[0])

    elif len(a) == 2:
      # From testcase
      debug("/ from testcase " + a[1] + " in " + a[0])
      tests.append(a[0] + ":" + a[1])
    else:
      # From method in class or from function
      debug("/ from method " + a[2] + " in testcase " +  a[1] + " in " + a[0])
      if a[1] == "":
        # test function, not method
        tests.append(a[0] + ":" + a[2])
      else:
        tests.append(a[0] + ":" + a[1] + "." + a[2])

  argv = ['nosetests']

  argv.extend(tests)


  if opts:
    options = shlex.split(opts)
    argv.extend(options)

  manager = DefaultPluginManager()
  manager.addPlugin(teamcity_plugin)
  config = MyConfig(plugins=manager)
  config.configure(argv)

  TestProgram(argv=argv, config=config, exit=False)
Exemplo n.º 6
0
def loadSource(fileName):
    baseName = os.path.basename(fileName)
    moduleName = os.path.splitext(baseName)[0]

    if os.path.isdir(fileName):
        fileName = fileName.rstrip('/\\') + os.path.sep

    # for users wanted to run unittests under django
    # because of django took advantage of module name
    settings_file = os.getenv('DJANGO_SETTINGS_MODULE')

    if settings_file and moduleName == "models":
        baseName = os.path.realpath(fileName)
        moduleName = ".".join((baseName.split(os.sep)[-2], "models"))
    else:
        path = fileName
        for p in roots:
            # Python 2.6+
            try:
                rel_path = os.path.relpath(fileName, start=p)
                if rel_path.find('..') == -1 and len(rel_path) < len(path):
                    path = rel_path
            except:
                pass  # relpath can raise an error in case of different drives for a path and start on Windows

        if path.endswith('.py'):
            path = path[0:-3]

        moduleName = path.replace('/', '.').replace('\\', '.')

    if moduleName in modules and len(
            sys.argv[1:-1]
    ) == 1:  # add unique number to prevent name collisions
        cnt = 2
        prefix = moduleName
        while getModuleName(prefix, cnt) in modules:
            cnt += 1
        moduleName = getModuleName(prefix, cnt)

    debug("/ Loading " + fileName + " as " + moduleName)

    try:
        module = imp.load_source(moduleName, fileName)
    except SystemError:  # probably failed because of the relative imports
        # first we import module with all its parents
        __import__(moduleName)

        # then load it by filename to be sure it is the one we need
        module = imp.load_source(moduleName, fileName)

    modules[moduleName] = module
    return module
Exemplo n.º 7
0
def loadSource(fileName):
  baseName = os.path.basename(fileName)
  moduleName = os.path.splitext(baseName)[0]

  if moduleName in modules:
    cnt = 2
    prefix = moduleName
    while getModuleName(prefix, cnt) in modules:
      cnt += 1
    moduleName = getModuleName(prefix, cnt)
  debug("/ Loading " + fileName + " as " + moduleName)
  module = imp.load_source(moduleName, fileName)
  modules[moduleName] = module
  return module
Exemplo n.º 8
0
def loadSource(fileName):
    baseName = os.path.basename(fileName)
    moduleName = os.path.splitext(baseName)[0]

    if moduleName in modules:
        cnt = 2
        prefix = moduleName
        while getModuleName(prefix, cnt) in modules:
            cnt += 1
        moduleName = getModuleName(prefix, cnt)
    debug("/ Loading " + fileName + " as " + moduleName)
    module = imp.load_source(moduleName, fileName)
    modules[moduleName] = module
    return module
Exemplo n.º 9
0
def loadSource(fileName):
    baseName = os.path.basename(fileName)
    moduleName = os.path.splitext(baseName)[0]

    if os.path.isdir(fileName):
        fileName = fileName.rstrip("/\\") + os.path.sep

    # for users wanted to run unittests under django
    # because of django took advantage of module name
    settings_file = os.getenv("DJANGO_SETTINGS_MODULE")

    if settings_file and moduleName == "models":
        baseName = os.path.realpath(fileName)
        moduleName = ".".join((baseName.split(os.sep)[-2], "models"))
    else:
        path = fileName
        for p in roots:
            # Python 2.6+
            try:
                rel_path = os.path.relpath(fileName, start=p)
                if rel_path.find("..") == -1 and len(rel_path) < len(path):
                    path = rel_path
            except:
                pass  # relpath can raise an error in case of different drives for a path and start on Windows

        if path.endswith(".py"):
            path = path[0:-3]

        moduleName = path.replace("/", ".").replace("\\", ".")

    if moduleName in modules and len(sys.argv[1:-1]) == 1:  # add unique number to prevent name collisions
        cnt = 2
        prefix = moduleName
        while getModuleName(prefix, cnt) in modules:
            cnt += 1
        moduleName = getModuleName(prefix, cnt)

    debug("/ Loading " + fileName + " as " + moduleName)

    try:
        module = imp.load_source(moduleName, fileName)
    except SystemError:  # probably failed because of the relative imports
        # first we import module with all its parents
        __import__(moduleName)

        # then load it by filename to be sure it is the one we need
        module = imp.load_source(moduleName, fileName)

    modules[moduleName] = module
    return module
Exemplo n.º 10
0
def loadSource(fileName):
  baseName = os.path.basename(fileName)
  moduleName = os.path.splitext(baseName)[0]

  # for users wanted to run unittests under django
  #because of django took advantage of module name
  settings_file = os.getenv('DJANGO_SETTINGS_MODULE')
  if settings_file and moduleName == "models":
    baseName = os.path.realpath(fileName)
    moduleName = ".".join((baseName.split(os.sep)[-2], "models"))

  if moduleName in modules and len(sys.argv[1:-1]) == 1: # add unique number to prevent name collisions
    cnt = 2
    prefix = moduleName
    while getModuleName(prefix, cnt) in modules:
      cnt += 1
    moduleName = getModuleName(prefix, cnt)
  debug("/ Loading " + fileName + " as " + moduleName)
  module = imp.load_source(moduleName, fileName)
  modules[moduleName] = module
  return module
Exemplo n.º 11
0
    arg = arg.strip()
    if len(arg) == 0:
      continue

    if arg.startswith("--"):
      options[arg[2:]] = True
      continue

    a = arg.split("::")
    if len(a) == 1:
      # From module or folder
      a_splitted = a[0].split("_args_separator_")  # ";" can't be used with bash, so we use "_args_separator_"
      if len(a_splitted) != 1:
        # means we have pattern to match against
        if os.path.isdir(a_splitted[0]):
          debug("/ from folder " + a_splitted[0] + ". Use pattern: " + a_splitted[1])
          modules = loadModulesFromFolderRec(a_splitted[0], a_splitted[1])
      else:
        if  os.path.isdir(a[0]):
          debug("/ from folder " + a[0])
          modules = loadModulesFromFolderRec(a[0])
        else:
          debug("/ from module " + a[0])
          modules = [loadSource(a[0])]

      for module in modules:
        all.addTests(testLoader.loadTestsFromModule(module))

    elif len(a) == 2:
      # From testcase
      debug("/ from testcase " + a[1] + " in " + a[0])
Exemplo n.º 12
0
if __name__ == "__main__":
    finder = doctest.DocTestFinder()

    for arg in sys.argv[1:]:
        arg = arg.strip()
        if len(arg) == 0:
            continue

        a = arg.split("::")
        if len(a) == 1:
            # From module or folder
            a_splitted = a[0].split(";")
            if len(a_splitted) != 1:
                # means we have pattern to match against
                if a_splitted[0].endswith("/"):
                    debug("/ from folder " + a_splitted[0] +
                          ". Use pattern: " + a_splitted[1])
                    modules = testFilesInFolderUsingPattern(
                        a_splitted[0], a_splitted[1])
            else:
                if a[0].endswith("/"):
                    debug("/ from folder " + a[0])
                    modules = testFilesInFolder(a[0])
                else:
                    # from file
                    debug("/ from module " + a[0])
                    # for doctests from non-python file
                    if a[0].rfind(".py") == -1:
                        testfile(a[0])
                        modules = []
                    else:
                        modules = [loadSource(a[0])]
Exemplo n.º 13
0
    arg = arg.strip()
    if len(arg) == 0:
      continue

    if arg.startswith("--"):
      options[arg[2:]] = True
      continue

    a = arg.split("::")
    if len(a) == 1:
      # From module or folder
      a_splitted = a[0].split("_args_separator_")  # ";" can't be used with bash, so we use "_args_separator_"
      if len(a_splitted) != 1:
        # means we have pattern to match against
        if a_splitted[0].endswith(os.path.sep):
          debug("/ from folder " + a_splitted[0] + ". Use pattern: " + a_splitted[1])
          modules = loadModulesFromFolderRec(a_splitted[0], a_splitted[1])
      else:
        if a[0].endswith(os.path.sep):
          debug("/ from folder " + a[0])
          modules = loadModulesFromFolderRec(a[0])
        else:
          debug("/ from module " + a[0])
          modules = [loadSource(a[0])]

      for module in modules:
        all.addTests(testLoader.loadTestsFromModule(module))

    elif len(a) == 2:
      # From testcase
      debug("/ from testcase " + a[1] + " in " + a[0])
Exemplo n.º 14
0
if __name__ == "__main__":
  finder = doctest.DocTestFinder()

  for arg in sys.argv[1:]:
    arg = arg.strip()
    if len(arg) == 0:
      continue

    a = arg.split("::")
    if len(a) == 1:
      # From module or folder
      a_splitted = a[0].split(";")
      if len(a_splitted) != 1:
        # means we have pattern to match against
        if a_splitted[0].endswith("/"):
          debug("/ from folder " + a_splitted[0] + ". Use pattern: " + a_splitted[1])
          modules = testFilesInFolderUsingPattern(a_splitted[0], a_splitted[1])
      else:
        if a[0].endswith("/"):
          debug("/ from folder " + a[0])
          modules = testFilesInFolder(a[0])
        else:
          # from file
          debug("/ from module " + a[0])
          # for doctests from non-python file
          if a[0].rfind(".py") == -1:
            testfile(a[0])
            modules = []
          else:
            modules = [loadSource(a[0])]
Exemplo n.º 15
0
def process_args():
  tests = Tests()
  prefix = ""
  if not sys.argv:
    return

  arg = sys.argv[1].strip()
  if not len(arg):
    return

  argument_list = arg.split("::")
  if len(argument_list) == 1:
    # From module or folder
    a_splitted = argument_list[0].split(";")
    if len(a_splitted) != 1:
      # means we have pattern to match against
      if a_splitted[0].endswith("/"):
        debug("/ from folder " + a_splitted[0] + ". Use pattern: " + a_splitted[1])
        prefix = a_splitted[0]
        register_tests_from_folder(tests, a_splitted[0], a_splitted[1])
    else:
      if argument_list[0].endswith("/"):
        debug("/ from folder " + argument_list[0])
        prefix = a_splitted[0]
        register_tests_from_folder(tests, argument_list[0])
      else:
        debug("/ from file " + argument_list[0])
        module = get_module(argument_list[0])
        register_tests_from_module(module, tests)

  elif len(argument_list) == 2:
    # From testcase
    debug("/ from test class " + argument_list[1] + " in " + argument_list[0])
    module = get_module(argument_list[0])
    klass = getattr(module, argument_list[1])
    tests.register(klass())
  else:
    # From method in class or from function
    module = get_module(argument_list[0])
    if argument_list[1] == "":
      debug("/ from function " + argument_list[2] + " in " + argument_list[0])
      # test function, not method
      test = getattr(module, argument_list[2])
    else:
      debug("/ from method " + argument_list[2] + " in class " +  argument_list[1] + " in " + argument_list[0])
      klass = getattr(module, argument_list[1])
      test = getattr(klass(), argument_list[2])
    tests.register([test])

  tests.run(reporter=TeamCityReporter(prefix))
Exemplo n.º 16
0
def process_args():
    tests = Tests()
    prefix = ""
    if not sys.argv:
        return

    arg = sys.argv[1].strip()
    if not len(arg):
        return

    argument_list = arg.split("::")
    if len(argument_list) == 1:
        # From module or folder
        a_splitted = argument_list[0].split(";")
        if len(a_splitted) != 1:
            # means we have pattern to match against
            if a_splitted[0].endswith("/"):
                debug("/ from folder " + a_splitted[0] + ". Use pattern: " +
                      a_splitted[1])
                prefix = a_splitted[0]
                register_tests_from_folder(tests, a_splitted[0], a_splitted[1])
        else:
            if argument_list[0].endswith("/"):
                debug("/ from folder " + argument_list[0])
                prefix = a_splitted[0]
                register_tests_from_folder(tests, argument_list[0])
            else:
                debug("/ from file " + argument_list[0])
                module = get_module(argument_list[0])
                register_tests_from_module(module, tests)

    elif len(argument_list) == 2:
        # From testcase
        debug("/ from test class " + argument_list[1] + " in " +
              argument_list[0])
        module = get_module(argument_list[0])
        klass = getattr(module, argument_list[1])
        tests.register(klass())
    else:
        # From method in class or from function
        module = get_module(argument_list[0])
        if argument_list[1] == "":
            debug("/ from function " + argument_list[2] + " in " +
                  argument_list[0])
            # test function, not method
            test = getattr(module, argument_list[2])
        else:
            debug("/ from method " + argument_list[2] + " in class " +
                  argument_list[1] + " in " + argument_list[0])
            klass = getattr(module, argument_list[1])
            test = getattr(klass(), argument_list[2])
        tests.register([test])

    tests.run(reporter=TeamCityReporter(prefix))