def test_ignore_auto_generated_computed_field(self): """ Check that we count custom fields with no module or studio not auto generated Having an xml_id but no existing module is consider as not belonging to a module """ f1 = self.create_field('x_invoice_count') self.create_xml_id('invoice_count', 'ir.model.fields', f1.id) cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual( cl.code.get('odoo/studio', 0), 0, 'Studio auto generated count field should not be counted in cloc') f2 = self.create_field('x_studio_custom_field') self.create_xml_id('studio_custom', 'ir.model.fields', f2.id) cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual(cl.code.get('odoo/studio', 0), 1, 'Count other studio computed field') self.create_field('x_custom_field') cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual(cl.code.get('odoo/studio', 0), 2, 'Count fields without xml_id') f4 = self.create_field('x_custom_field_export') self.create_xml_id('studio_custom', 'ir.model.fields', f4.id, '__export__') cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual(cl.code.get('odoo/studio', 0), 3, 'Count fields with xml_id but without module')
def test_count_attachment_imported_module(self): manifest_content = json.dumps({ 'name': 'test_imported_module', 'description': 'Test', 'assets': { 'web.assets_backend': [ 'test_imported_module/static/src/js/test.js', 'test_imported_module/static/src/css/test.scss', ] }, 'license': 'LGPL-3', }) stream = BytesIO() with ZipFile(stream, 'w') as archive: archive.writestr('test_imported_module/__manifest__.py', manifest_content) archive.writestr('test_imported_module/static/src/js/test.js', test_cloc.JS_TEST) archive.writestr('test_imported_module/static/src/js/test.scss', test_cloc.SCSS_TEST) archive.writestr('test_imported_module/static/src/js/test.xml', VALID_XML) # Import test module self.env['ir.module.module'].import_zipfile(stream) cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual(cl.code.get('test_imported_module', 0), 35)
def test_no_custo_install(self): """ Make sure after the installation of module no database customization is counted """ cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual( cl.code.get('odoo/studio', 0), 0, 'Module should not generate customization in database')
def test_parser(self): cl = cloc.Cloc() xml_count = cl.parse_xml(XML_TEST) self.assertEqual(xml_count, (18, 31)) py_count = cl.parse_py(PY_TEST_NO_RETURN) self.assertEqual(py_count, (2, 2)) py_count = cl.parse_py(PY_TEST) self.assertEqual(py_count, (8, 16)) js_count = cl.parse_js(JS_TEST) self.assertEqual(js_count, (10, 17))
def test_fields_from_import_module(self): """ Check that custom computed fields installed with an imported module is counted as customization """ self.env['ir.module.module'].create({ 'name': 'imported_module', 'state': 'installed', 'imported': True, }) f1 = self.create_field('x_imported_field') self.create_xml_id('import_field', f1.id, 'imported_module') cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual(cl.code.get('imported_module', 0), 1, 'Count fields with xml_id of imported module') f2 = self.create_field('x_base_field') self.create_xml_id('base_field', f2.id, 'base') cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual(cl.code.get('base', 0), 0, "Don't count fields from standard module")
def test_parser(self): cl = cloc.Cloc() xml_count = cl.parse_xml(XML_TEST) self.assertEqual(xml_count, (18, 31)) py_count = cl.parse_py(PY_TEST_NO_RETURN) self.assertEqual(py_count, (2, 2)) py_count = cl.parse_py(PY_TEST) if sys.version_info >= (3, 8, 0): # Multi line str lineno return the begining of the str # in python 3.8, it result in a different count for # multi str used in expressions self.assertEqual(py_count, (7, 16)) else: self.assertEqual(py_count, (8, 16)) js_count = cl.parse_js(JS_TEST) self.assertEqual(js_count, (10, 17))
def _get_message(self): msg = super()._get_message() ICP = self.env["ir.config_parameter"] if ICP.get_param( 'publisher_warranty.maintenance_disable') is not False: return msg msg['maintenance'] = { "version": cloc.VERSION, } try: c = cloc.Cloc() c.count_env(self.env) if c.code: msg["maintenance"]["modules"] = c.code if c.errors: msg["maintenance"]["errors"] = list(c.errors.keys()) except Exception: msg["maintenance"]["errors"] = ['cloc/error'] return msg
def run(self, args): parser = argparse.ArgumentParser( prog="%s cloc" % sys.argv[0].split(os.path.sep)[-1], description=textwrap.dedent(self.__doc__), formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument('--database', '-d', dest="database", help="Database name") parser.add_argument('--path', '-p', action='append', help="File or directory path") parser.add_argument('--verbose', '-v', action='count', default=0) opt, unknown = parser.parse_known_args(args) if not opt.database and not opt.path: parser.print_help() sys.exit() c = cloc.Cloc() if opt.database: config.parse_config(['-d', opt.database] + unknown) c.count_database(opt.database) if opt.path: for i in opt.path: c.count_path(i) c.report(opt.verbose)
def test_count_qweb_imported_module(self): self.env['ir.module.module'].create({ 'author': 'Odoo', 'imported': True, 'latest_version': '15.0.1.0.0', 'name': 'test_imported_module', 'state': 'installed', 'summary': 'Test imported module for cloc', }) # Studio module does not exist at this stage, so we simulate it # Check for existing module in case the test run on an existing database if not self.env['ir.module.module'].search( [('name', '=', 'studio_customization')]): self.env['ir.module.module'].create({ 'author': 'Odoo', 'imported': True, 'latest_version': '15.0.1.0.0', 'name': 'studio_customization', 'state': 'installed', 'summary': 'Studio Customization', }) qweb_view = self.env['ir.ui.view'].create({ "name": "Qweb Test", "type": "qweb", "mode": "primary", "arch_base": "<html>\n <body>\n <t t-out=\"Hello World\"/>\n </body>\n</html>", }) self.create_xml_id("qweb_view_test", 'ir.ui.view', qweb_view.id, 'test_imported_module') # Add qweb view from non imported module qweb_view = self.env['ir.ui.view'].create({ "name": "Qweb Test", "type": "qweb", "arch_base": "<html>\n <body>\n <t t-out=\"Hello World\"/>\n </body>\n</html>", }) self.create_xml_id("qweb_view_test", 'ir.ui.view', qweb_view.id) # Add form view from module form_view = self.env['ir.ui.view'].create({ "name": "Test partner", "type": "form", "model": "res.partner", "arch_base": "<form>\n <field name=\"name\" \n invisible=\"1\" />\n</form>", }) self.create_xml_id("form_view_test", 'ir.ui.view', form_view.id, 'test_imported_module') cl = cloc.Cloc() cl.count_customization(self.env) self.assertEqual(cl.code.get('test_imported_module', 0), 5, "Count only qweb view from imported module") self.assertEqual(cl.code.get('studio_customization', 0), 0, "Do not count from studio_customization module")