コード例 #1
0
def load_test_file_py(registry, test_file):
    threading.currentThread().testing = True
    try:
        test_path, _ = os.path.splitext(os.path.abspath(test_file))
        for mod in [m for m in get_modules() if '/%s/' % m in test_file]:
            for mod_mod in get_test_modules(mod):
                mod_path, _ = os.path.splitext(getattr(mod_mod, '__file__',
                                                       ''))
                if test_path == mod_path:
                    suite = unittest.TestSuite()
                    for t in unittest.TestLoader().loadTestsFromModule(
                            mod_mod):
                        suite.addTest(t)
                    _logger.log(logging.INFO, 'running tests %s.',
                                mod_mod.__name__)
                    stream = eagle.modules.module.TestStream()
                    result = unittest.TextTestRunner(verbosity=2,
                                                     stream=stream).run(suite)
                    success = result.wasSuccessful()
                    if hasattr(registry._assertion_report, 'report_result'):
                        registry._assertion_report.report_result(success)
                    if not success:
                        _logger.error(
                            '%s: at least one error occurred in a test',
                            test_file)
                    return
    finally:
        threading.currentThread().testing = False
コード例 #2
0
ファイル: command.py プロジェクト: babarlhr/eagle13
def main():
    args = sys.argv[1:]

    # The only shared option is '--addons-path=' needed to discover additional
    # commands from modules
    if len(args) > 1 and args[0].startswith('--addons-path=') and not args[1].startswith("-"):
        # parse only the addons-path, do not setup the logger...
        eagle.tools.config._parse_config([args[0]])
        args = args[1:]

    # Default legacy command
    command = "server"

    # TODO: find a way to properly discover addons subcommands without importing the world
    # Subcommand discovery
    if len(args) and not args[0].startswith("-"):
        logging.disable(logging.CRITICAL)
        for module in get_modules():
            if isdir(joinpath(get_module_path(module), 'cli')):
                __import__('eagle.addons.' + module)
        logging.disable(logging.NOTSET)
        command = args[0]
        args = args[1:]

    if command in commands:
        o = commands[command]()
        o.run(args)
    else:
        sys.exit('Unknow command %r' % (command,))
コード例 #3
0
    def test_pylint(self):
        if pylint is None:
            self._skip_test('please install pylint')
        required_pylint_version = LooseVersion('1.6.4')
        if sys.version_info >= (3, 6):
            required_pylint_version = LooseVersion('1.7.0')
        if LooseVersion(getattr(pylint, '__version__',
                                '0.0.1')) < required_pylint_version:
            self._skip_test('please upgrade pylint to >= %s' %
                            required_pylint_version)

        paths = [tools.config['root_path']]
        for module in get_modules():
            module_path = get_module_path(module)
            if not module_path.startswith(
                    join(tools.config['root_path'], 'addons')):
                paths.append(module_path)

        options = [
            '--rcfile=%s' % os.devnull, '--disable=all',
            '--enable=%s' % ','.join(self.ENABLED_CODES), '--reports=n',
            "--msg-template='{msg} ({msg_id}) at {path}:{line}'",
            '--load-plugins=pylint.extensions.bad_builtin,_eagle_checkers',
            '--bad-functions=%s' % ','.join(self.BAD_FUNCTIONS),
            '--deprecated-modules=%s' % ','.join(self.BAD_MODULES)
        ]

        pypath = HERE + os.pathsep + os.environ.get('PYTHONPATH', '')
        env = dict(os.environ, PYTHONPATH=pypath)
        try:
            pylint_bin = tools.which('pylint')
            process = subprocess.Popen(
                [pylint_bin] + options + paths,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                env=env,
            )
        except (OSError, IOError):
            self._skip_test('pylint executable not found in the path')
        else:
            out, err = process.communicate()
            if process.returncode:
                self.fail("pylint test failed:\n" +
                          (b"\n" + out + b"\n" + err).decode('utf-8').strip())
コード例 #4
0
ファイル: ir_module.py プロジェクト: rapidgrps/eagle-12.3
    def update_list(self):
        res = [0, 0]  # [update, add]

        default_version = modules.adapt_version('1.0')
        known_mods = self.with_context(lang=None).search([])
        known_mods_names = {mod.name: mod for mod in known_mods}

        # iterate through detected modules and update/create them in db
        for mod_name in modules.get_modules():
            mod = known_mods_names.get(mod_name)
            terp = self.get_module_info(mod_name)
            values = self.get_values_from_terp(terp)

            if mod:
                updated_values = {}
                for key in values:
                    old = getattr(mod, key)
                    updated = tools.ustr(values[key]) if isinstance(
                        values[key], pycompat.string_types) else values[key]
                    if (old or updated) and updated != old:
                        updated_values[key] = values[key]
                if terp.get('installable',
                            True) and mod.state == 'uninstallable':
                    updated_values['state'] = 'uninstalled'
                if parse_version(terp.get(
                        'version', default_version)) > parse_version(
                            mod.latest_version or default_version):
                    res[0] += 1
                if updated_values:
                    mod.write(updated_values)
            else:
                mod_path = modules.get_module_path(mod_name)
                if not mod_path or not terp:
                    continue
                state = "uninstalled" if terp.get('installable',
                                                  True) else "uninstallable"
                mod = self.create(dict(name=mod_name, state=state, **values))
                res[1] += 1

            mod._update_dependencies(terp.get('depends', []))
            mod._update_exclusions(terp.get('excludes', []))
            mod._update_category(terp.get('category', 'Uncategorized'))

        return res
コード例 #5
0
    def test_ecmascript_version(self):
        """ Test that there is no unsupported ecmascript in javascript files """

        black_re = re.compile(r'summernote.+(intro\.js|outro.js)$')

        mod_paths = [get_module_path(m) for m in get_modules()]
        files_to_check = []
        for p in mod_paths:
            for dp, _, file_names in os.walk(p):
                if 'static/test' in dp or "static/src/tests" in dp:
                    continue
                for fn in file_names:
                    fullpath_name = os.path.join(dp, fn)
                    if fullpath_name.endswith(
                            '.js') and not black_re.search(fullpath_name):
                        files_to_check.append(fullpath_name)

        _logger.info('Testing %s js files', len(files_to_check))
        cmd = [es_check, MAX_ES_VERSION] + files_to_check
        process = subprocess.Popen(cmd,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        out, err = process.communicate()
        self.assertEqual(process.returncode, 0, msg=out.decode())