Exemple #1
0
    def configure(self, options, config):
        """
        Coinfigure plugin.

        A plugin's configure() method receives the parsed OptionParser options
        object, as well as the current config object. Plugins should configure
        their behavior based on the user-selected settings, and may raise
        exceptions if the configured behavior is nonsensical.
        """
        super(XCase, self).configure(options, config)
        if not self.enabled:
            return
        self.options = options
        self.config = config

        # Check for Test Env
        if not options.test_env:
            path = find_test_project_from_cwd()
            if path:
                options.test_env = path

        if options.test_env:
            self._configure_test_env()

        conf.settings.verbosity = options.verbosity
        if options.xcase_project_path:
            conf.load_settings(options.xcase_project_path)
        else:
            conf.load_settings(find_test_project_from_cwd())

        if options.xcase_workspace:
            conf.settings.WORKSPACE = options.xcase_workspace
        makedirs(conf.settings.WORKSPACE)
Exemple #2
0
    def copy(self, todir):
        target = guess_target(todir, self.source, self.target)

        template_dirs = [os.path.abspath(os.path.dirname(self.source))]
        if settings.fixtures_dir:
            template_dirs.append(settings.fixtures_dir)

        jinja2_env = Environment(loader=FileSystemLoader(template_dirs))
        template = jinja2_env.get_template(os.path.basename(self.source))
        text = template.render()

        makedirs(os.path.dirname(target))
        with open(target, 'w') as writer:
            writer.write(text)
Exemple #3
0
    def parseArgs(self, argv):
        if len(argv) > 1 and argv[1].lower() == 'discover':
            self._do_discovery(argv[2:])
            return

        parser = argparse.ArgumentParser()
        parser.add_argument('-V', '--version', action='version',
                            version=__version__)
        parser.add_argument('-q', '--quiet', action='store_true',
                            help="minimal output")
        parser.add_argument('-v', '--verbose', action='count',
                            help="verbose output")
        parser.add_argument('-f', '--failfast', action='store_true',
                            help="stop on the first failure")
        parser.add_argument('-c', '--catch', action='store_true',
                            help="catch ctrl-c and display results")
        parser.add_argument('-b', '--buffer', action='store_true',
                            help="buffer stdout and stderr during test runs")
        parser.add_argument('tests', nargs='*')
        parser.add_argument('--test-project-path',
                            default=os.environ.get(ENVIRONMENT_VARIABLE),
                            help='set test project path where settings.py '
                            'locate. [%s]' % ENVIRONMENT_VARIABLE)
        parser.add_argument('--test-workspace', type=os.path.abspath,
                            help='set test workspace path')
        parser.add_argument('--with-xunit', action='store_true',
                            help='provides test resutls in standard XUnit XML '
                            'format')
        parser.add_argument('--xunit-file',
                            type=os.path.abspath, default='xunit.xml',
                            help='Path to xml file to store the xunit report.'
                            'Default is xunit.xml in the working directory')

        opts = parser.parse_args()

        # super class options
        if opts.quiet:
            self.verbosity = 0
        elif opts.verbose:
            # default verbosity is 1
            self.verbosity = opts.verbose + 1
        self.failfast = opts.failfast
        self.catchbreak = opts.catch
        self.buffer = opts.buffer

        # additional options
        if opts.with_xunit:
            if not os.access(os.path.dirname(opts.xunit_file), os.W_OK):
                print >> sys.stderr, "Permission denied:", opts.xunit_file
                sys.exit(1)
            from itest.result import XunitTestResult
            self.testRunner.resultclass = XunitTestResult
            self.testRunner.resultclass.xunit_file = opts.xunit_file
        else:
            self.testRunner.resultclass = TextTestResult

        if opts.test_project_path:
            conf.load_settings(opts.test_project_path)
        else:
            conf.load_settings(find_test_project_from_cwd())

        conf.settings.verbosity = self.verbosity

        if opts.test_workspace:
            conf.settings.WORKSPACE = opts.test_workspace
        makedirs(conf.settings.WORKSPACE)

        # copy from super class
        if len(opts.tests) == 0 and self.defaultTest is None:
            # createTests will load tests from self.module
            self.testNames = None
        elif len(opts.tests) > 0:
            self.testNames = opts.tests
            if __name__ == '__main__':
                # to support python -m unittest ...
                self.module = None
        else:
            self.testNames = (self.defaultTest,)
        self.createTests()
Exemple #4
0
 def copy(self, todir):
     target = os.path.join(todir, self.target)
     makedirs(os.path.dirname(target))
     with open(target, 'w') as writer:
         writer.write(self.text)
Exemple #5
0
 def copy(self, todir):
     target = guess_target(todir,
                           self.source,
                           self.target).rstrip(os.path.sep)
     makedirs(os.path.dirname(target))
     shutil.copytree(self.source, target)