Skip to content

Commit

Permalink
Merge branch 'master' into test_inherit_views_on_test_all_views
Browse files Browse the repository at this point in the history
  • Loading branch information
polsala authored Jun 28, 2023
2 parents 3b03f47 + 7bbe755 commit 955dea4
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bumpversion]
current_version = 1.14.0
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: DESTRAL_RELEASE

on:
push:
tags:
- 'v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+'
- 'v[0-9]+\.[0-9]+\.[0-9]+'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 2.7
uses: actions/setup-python@v2
with:
python-version: '2.7'
- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1
with:
strip_v: false
- name: Creating a realease/pre-release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{steps.tag.outputs.tag}}
draft: false
prerelease: ${{ contains(github.ref, '-rc') }}
generate_release_notes: true
- name: Publish a Python distribution to PyPI
if: ${{ contains(github.ref, '-rc') }} == false
uses: conchylicultor/pypi-build-publish@v1
with:
pypi-token: ${{ secrets.PYPI_TOKEN }}
61 changes: 61 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: GISCE_DESTRAL_VERION
on:
push:
branches: [ master ]
jobs:
bump:
runs-on: ubuntu-latest
if: ${{ !startsWith(github.event.head_commit.message, 'Bump to v') }}
steps:
- uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_PRIVATE }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Setup git
run: |
git config --global user.email "[email protected]"
git config --global user.name "giscegit"
- name: Install python packages
run: |
pip install bump2version
pip install giscemultitools
- name: Get PR info
env:
GITHUB_TOKEN: ${{ secrets.GH_GIT_TOKEN }}
WORKSPACE: ${{github.workspace}}
run: |
echo 'PR_INFO<<EOF' >> $GITHUB_ENV
gisce_github get-commits-sha-from-merge-commit --owner gisce --repository destral --sha $GITHUB_SHA >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Retrive info
run: |
eval `ssh-agent -s`
ssh-add - <<< '${{ secrets.SSH_PRIVATE }}'
pr_labels=$( echo '${{ env.PR_INFO }}' | jq -r '.pullRequest.labels' )
is_minor=false
is_major=false
is_patch=false
for label in echo $( echo $pr_labels | jq -r '.[].name' ); do
if [[ $label == 'minor' ]]; then
is_minor=true
elif [[ $label == 'major' ]]; then
is_major=true
elif [[ $label == 'patch' ]]; then
is_patch=true
fi
done
VERSION_TYPE=false
if [[ $is_major == true ]]; then
VERSION_TYPE="major"
elif [[ $is_minor == true ]]; then
VERSION_TYPE="minor"
elif [[ $is_patch == true ]]; then
VERSION_TYPE="patch"
fi
if [[ $VERSION_TYPE != false ]]; then
bump2version $VERSION_TYPE --tag --commit -m "Bump to v{new_version}" setup.py
git push origin master --tags
fi
26 changes: 18 additions & 8 deletions destral/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import subprocess
import logging
from six.moves.urllib import request as urllib2
import requests

import click
from destral.utils import *
Expand All @@ -28,14 +28,21 @@
@click.option('--all-tests', '-a', type=click.BOOL, default=False, is_flag=True)
@click.option('--enable-coverage', type=click.BOOL, default=False, is_flag=True)
@click.option('--report-coverage', type=click.BOOL, default=False, is_flag=True)
@click.option('--report-junitxml', type=click.STRING, nargs=1, default=False)
@click.option('--report-junitxml', type=click.STRING, nargs=1, default="")
@click.option('--database', type=click.STRING, nargs=1, default=None)
@click.option('--dropdb/--no-dropdb', default=True)
@click.option('--requirements/--no-requirements', default=True)
@click.option('--enable-lint', type=click.BOOL, default=False, is_flag=True)
@click.option('--constraints-file', type=click.STRING, nargs=1, default="")
def destral(modules, tests, all_tests=None, enable_coverage=None,
report_coverage=None, report_junitxml=None, dropdb=None,
requirements=None, **kwargs):
os.environ['OPENERP_DESTRAL_MODE'] = "1"
enable_lint = kwargs.pop('enable_lint')
constraints_file = kwargs.pop('constraints_file')
database = kwargs.pop('database')
if database:
os.environ['OPENERP_DB_NAME'] = database
sys.argv = sys.argv[:1]
service = OpenERPService()
if report_junitxml:
Expand All @@ -60,22 +67,21 @@ def destral(modules, tests, all_tests=None, enable_coverage=None,
repo=repository,
pr_number=ci_pull_request
)
req = urllib2.Request(
req = requests.get(
url,
headers={
'Authorization': 'token {0}'.format(token),
'Accept': 'application/vnd.github.patch'
}
)
f = urllib2.urlopen(req)
paths = find_files(f.read())
paths = find_files(req.text)
logger.info('Files from Pull Request: {0}: {1}'.format(
ci_pull_request, ', '.join(paths)
))
else:
paths = subprocess.check_output([
"git", "diff", "--name-only", "HEAD~1..HEAD"
])
]).decode('utf-8')
paths = [x for x in paths.split('\n') if x]
logger.info('Files from last commit: {}'.format(
', '.join(paths)
Expand Down Expand Up @@ -122,7 +128,7 @@ def destral(modules, tests, all_tests=None, enable_coverage=None,
for module in modules_to_test:
with RestorePatchedRegisterAll():
if requirements:
install_requirements(module, addons_path)
install_requirements(module, addons_path, constraints_file=constraints_file)
spec_suite = get_spec_suite(os.path.join(addons_path, module))
if spec_suite:
logger.info('Spec testing module %s', module)
Expand Down Expand Up @@ -166,8 +172,12 @@ def destral(modules, tests, all_tests=None, enable_coverage=None,
if modules_path:
run_linter(modules_path)

return_code = 0
if not all(results):
sys.exit(1)
return_code = 1

service.shutdown(return_code)
sys.exit(return_code)


if __name__ == '__main__':
Expand Down
21 changes: 18 additions & 3 deletions destral/openerp.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ def install_module(self, module):
unmet_packages.append(dep_mod.name)
mod_obj.download(cursor, uid, ids)
cursor.commit()
self.db, self.pool = pooler.restart_pool(
self.config['db_name'], update_module=True
)
try:
self.db, self.pool = pooler.restart_pool(
self.config['db_name'], update_module=True
)
except Exception:
self.shutdown(1)
raise

def enable_admin(self, password='admin'):
from destral.transaction import Transaction
Expand All @@ -173,3 +177,14 @@ def enable_admin(self, password='admin'):
logger.info(
'User admin enabled with password: %s on %s',
password, txn.cursor.dbname)

def shutdown(self, return_code):
try:
from signals import SHUTDOWN_REQUEST
SHUTDOWN_REQUEST.send(exit_code=return_code)
except TypeError:
# Backwards compatible
logger.warning('Old SHUTDOWN signal API withoud return_code')
SHUTDOWN_REQUEST.send(None)
except ImportError:
pass
2 changes: 1 addition & 1 deletion destral/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, connection, cursor):
def __getattr__(self, item):
return getattr(self._connection, item)

def cursor(self, serialized=False):
def cursor(self, serialized=False, *args, **kwargs):
"""Wrapped function to return the same cursor
"""
return self._cursor
Expand Down
33 changes: 23 additions & 10 deletions destral/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import unittest
import sys

from destral.junitxml_testing import JUnitXMLResult, LoggerStream
from destral.junitxml_testing import JUnitXMLApplicationFactory
Expand Down Expand Up @@ -74,6 +75,19 @@ def _handleClassSetUp(self, test, result):
class OOTestLoader(unittest.TestLoader):
suiteClass = OOTestSuite

@staticmethod
def check_suite(suite):
if sys.version_info >= (3, 6, 0):
from unittest.loader import _FailedTest
if suite._tests and isinstance(suite._tests[0], _FailedTest):
raise AttributeError
return suite

def loadTestsFromName(self, name, module=None):
suite = super(OOTestLoader, self).loadTestsFromName(name, module)
return self.check_suite(suite)



class OOTestCase(unittest.TestCase):
"""Base class to inherit test cases from for OpenERP Testing Framework.
Expand Down Expand Up @@ -134,10 +148,11 @@ def test_all_views(self):
'View (xml id: %s) references model %s which does '
'not exist' % (view_xml_name, view.model)
)
logger.info('Testing view %s (id: %s)', view.name, view.id)
logger.info('Testing view %s (id: %s) v%s', view.name, view.id, view.version)
model.fields_view_get(txn.cursor, txn.user, view.id,
view.type)
view.type, version=view.version)
if view.inherit_id:
version = view.version
while view.inherit_id:
try:
model.fields_view_get(
Expand All @@ -150,13 +165,11 @@ def test_all_views(self):
view.name, view.id
)
view = view.inherit_id
model.fields_view_get(
txn.cursor, txn.user, view.id, view.type
)
logger.info(
'Testing main view %s (id: %s)',
view.name, view.id
)

model.fields_view_get(txn.cursor, txn.user, view.id,
view.type, version=version)
logger.info('Testing main view %s (id: %s) v%s',
view.name, view.id, version)

def test_access_rules(self):
"""Test access rules for all the models created in the module
Expand Down Expand Up @@ -201,7 +214,7 @@ def test_translate_modules(self):
from os.path import join, isdir
from tools import trans_export
from six.moves import StringIO
from utils import compare_pofiles, TempDir
from destral.utils import compare_pofiles, TempDir

if not self.config['testing_langs']:
logger.warning(
Expand Down
34 changes: 24 additions & 10 deletions destral/transaction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from threading import local
import six


from destral.openerp import OpenERPService
from signals import DB_CURSOR_EXECUTE


class Singleton(type):
Expand All @@ -19,10 +21,10 @@ def __call__(mcs, *args, **kwargs):
return mcs.instance


@six.add_metaclass(Singleton)
class Transaction(local):
"""Transaction object
"""
__metaclass__ = Singleton

database = None
service = None
Expand All @@ -46,13 +48,19 @@ def start(self, database_name, user=1, context=None):
self.pool = self.service.pool
self.cursor = self.service.db.cursor()
self.user = user
self.context = context if context is not None else self.get_context()
try:
receivers = DB_CURSOR_EXECUTE.receivers
DB_CURSOR_EXECUTE.receivers = {}
self.context = context if context is not None else self.get_context()
finally:
DB_CURSOR_EXECUTE.receivers = receivers
return self

def stop(self):
"""Stop the transaction.
"""
self.cursor.close()
if self.cursor is not None:
self.cursor.close()
self.service = None
self.cursor = None
self.user = None
Expand All @@ -74,10 +82,16 @@ def __enter__(self):
def __exit__(self, type, value, traceback):
self.stop()

def _assert_stopped(self):
assert self.service is None
assert self.database is None
assert self.cursor is None
assert self.pool is None
assert self.user is None
assert self.context is None
def _assert_stopped(self, deep=False):
try:
assert self.service is None
assert self.database is None
assert self.cursor is None
assert self.pool is None
assert self.user is None
assert self.context is None
except AssertionError as ae:
if not deep:
self.stop()
return self._assert_stopped(True)
raise ae
11 changes: 7 additions & 4 deletions destral/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ def find_files(diff):
"""Return all the files implicated in a diff
"""
paths = []
for line in re.findall("--- a/.*|\+\+\+ b/.*", diff):
line = '/'.join(line.split('/')[1:])
for line in re.findall(u"--- a/.*|\+\+\+ b/.*", diff):
line = u'/'.join(line.split(u'/')[1:])
paths.append(line)
return list(set(paths))


def install_requirements(module, addons_path):
def install_requirements(module, addons_path, constraints_file=''):
"""Install module requirements and its dependecies
"""
pip = os.path.join(sys.prefix, 'bin', 'pip')
Expand All @@ -142,7 +142,10 @@ def install_requirements(module, addons_path):
for req in requirements_files:
if os.path.exists(req):
logger.info('Requirements file %s found. Installing...', req)
subprocess.check_call([pip, "install", "-r", req])
if constraints_file:
subprocess.check_call([pip, "install", "-c", constraints_file, "-r", req])
else:
subprocess.check_call([pip, "install", "-r", req])


def coverage_modules_path(modules_to_test, addons_path):
Expand Down
Loading

0 comments on commit 955dea4

Please sign in to comment.