<commit_before>from openerp.tests import common
from datetime import datetime as dt
from dateutil.relativedelta import relativedelta as rd
from openerp import tools
from openerp.osv import orm, fields, osv

import logging        
from pprint import pprint as pp
_logger = logging.getLogger(__name__)

from faker import Faker
fake = Faker()
seed = fake.random_int(min=0, max=9999999)
def next_seed():
    global seed
    seed += 1
    return seed

class BaseTest(common.SingleTransactionCase):
    def setUp(self):
        global cr, uid, seed
        global patient_pool, location_pool, pos_pool, user_pool, imd_pool, activity_pool, device_type_pool, device_pool
        global pos_id, ward_location_ids, bed_location_ids, adt_user_id, nurse_user_ids
    
        cr, uid = self.cr, self.uid
              
        patient_pool = self.registry('t4.clinical.patient')
        location_pool = self.registry('t4.clinical.location')
        pos_pool = self.registry('t4.clinical.pos')
        activity_pool = self.registry('t4.activity')
        user_pool = self.registry('res.users')
        imd_pool = self.registry('ir.model.data')
        device_type_pool = self.registry('t4.clinical.device.type')
        device_pool = self.registry('t4.clinical.device')
        super(BaseTest, self).setUp()
        
    def create_activity(self, cr, uid, data_model, vals_activity={}, vals_data={}, context=None):
        model_pool = self.registry(data_model)
        activity_id = model_pool.create_activity(cr, uid, vals_activity, vals_data, context)
        _logger.info("Activity created id=%s, data_model=%s\n vals_activity: %s\n vals_data: %s" 
                     % (activity_id, data_model, vals_activity, vals_data))
        activity = activity_pool.browse(cr, uid, activity_id)

        # tests
        self.assertTrue(activity.state == "new", 
                        "activity.state (%s) != 'new'" 
                        % (activity.state)) 
        self.assertTrue(activity.data_model == model_pool._name, 
                        "activity.data_model (%s) != model_pool._name (%s)" 
                        % (activity.data_model, model_pool._name))        <commit_msg>t4clinical BaseTest and inherited classes follow server parameter --test-commit<commit_after>from openerp.tests import common
from datetime import datetime as dt
from dateutil.relativedelta import relativedelta as rd
from openerp import tools
from openerp.tools import config 
from openerp.osv import orm, fields, osv

import logging        
from pprint import pprint as pp
_logger = logging.getLogger(__name__)

from faker import Faker
fake = Faker()
seed = fake.random_int(min=0, max=9999999)
def next_seed():
    global seed
    seed += 1
    return seed

class BaseTest(common.SingleTransactionCase):
    @classmethod
    def tearDownClass(cls):
        if config['test_commit']:
            cls.cr.commit()
            print "COMMIT"
        else:
            cls.cr.rollback()
            print "ROLLBACK"
        cls.cr.close()
        
    def setUp(self):
        global cr, uid, seed
        global patient_pool, location_pool, pos_pool, user_pool, imd_pool, activity_pool, device_type_pool, device_pool
        global pos_id, ward_location_ids, bed_location_ids, adt_user_id, nurse_user_ids
    
        cr, uid = self.cr, self.uid
              
        patient_pool = self.registry('t4.clinical.patient')
        location_pool = self.registry('t4.clinical.location')
        pos_pool = self.registry('t4.clinical.pos')
        activity_pool = self.registry('t4.activity')
        user_pool = self.registry('res.users')
        imd_pool = self.registry('ir.model.data')
        device_type_pool = self.registry('t4.clinical.device.type')
        device_pool = self.registry('t4.clinical.device')
        super(BaseTest, self).setUp()
        
    def create_activity(self, cr, uid, data_model, vals_activity={}, vals_data={}, context=None):
        model_pool = self.registry(data_model)
        activity_id = model_pool.create_activity(cr, uid, vals_activity, vals_data, context)
        _logger.info("Activity created id=%s, data_model=%s\n vals_activity: %s\n vals_data: %s" 
                     % (activity_id, data_model, vals_activity, vals_data))
        activity = activity_pool.browse(cr, uid, activity_id)

        # tests
        self.assertTrue(activity.state == "new", 
                        "activity.state (%s) != 'new'" 
                        % (activity.state)) 
        self.assertTrue(activity.data_model == model_pool._name, 
                        "activity.data_model (%s) != model_pool._name (%s)" 
                        % (activity.data_model, model_pool._name))        
{'fraction_non_alphanumeric': 0.10322030283642568, 'fraction_numerical': 0.006611217743655364, 'mean_word_length': 2.7104430379746836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506780', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1387, 'n_words': 315}