class Test_Log(unittest.TestCase):
    
    def setUp(self):
        self.logdir = "/tmp/log"
        self.log = Log(verbosity=10,
                       cacheflag=True,logdir="/tmp/log",
                       pidlogname=False,proclogname=False,
                       reset="") # this forces the singleton to allow a new instance

    def test_debug(self):
        self.log.log(thisfuncname(),7)
        
        logfile = os_file_to_list(self.log.logpath)
        
        self.assertEquals(logfile[0].split("|")[2].strip(),"DEBUG")
        
    def test_extra_msg(self): 
        self.log.log(thisfuncname(),3,foobar='barfoo')
        expected_results = "[('foobar','barfoo')]"
        logfile = os_file_to_list(self.log.logpath)
        
        self.assertEquals(logfile[0].split("|")[9].strip(),expected_results)
        
    def tearDown(self):
        self.log.log_clean()
        pass
class Test_Log_LineNumber(Test_Log_Base):
    def setUp(self):
        self.log = Log()
        self.log.config = OrderedDict([('linenum',5)]) 
        self.log.cacheflag=True
        self.log.startlog()
    
    def test_(self):
        def myfunc(arg1,arg2):
            self.log.log(PRIORITY.SUCCESS,msg="this is a test")            
        myfunc('foo','bar')
        
        # not testing for a specific line number as it will be too brittle a test
        self.assertTrue(isint(self.log.cache[0][0]))
class Test_Log_Multiple_Entries(unittest.TestCase):
    
    def setUp(self):
        
        self.logdir = "/tmp/log"
        self.log = Log(verbosity=10,
                       cacheflag=True,logdir="/tmp/log",
                       pidlogname=False,proclogname=False,
                       reset="")
        
        @logger(self.log)
        def func1(*args,**kwargs):
            return(100)
        
        self.func1  = func1
        
    
    def test_1000msg(self):
        
        for i in range(1000):
            self.log.log(thisfuncname(),7,)
            
        self.assertEqual(len(self.log.cache),1000)
        
        self.log.logfile.close()
        
        self.assertEqual(self.log.log_file_length(),999)
        self.log.log_clean()
        

    def test_1000msg_logger(self):
        
        for i in range(1000):
            self.func1()
        
        
        pid = os.getpid()
        self.assertEqual(self.log.stats[str(pid)]['func1']['no'],1000)
        self.log.log_clean()
class Test_Misc(unittest.TestCase):
    
    def setUp(self):
        self.logdir = "/tmp/log"
        self.log = Log(verbosity=10,
                       cacheflag=True,logdir="/tmp/log",
                       pidlogname=False,proclogname=False,
                       reset="") # this forces the singleton to allow a new instance
        
    def test_func_arg(self):
        
        from database_table_util import tbl_col_add
        self.log.log(self,4,func=tbl_col_add,current_value="aaa",new_value="bbb")
        
        logfile = os_file_to_list(self.log.logpath)
        
        expected_results = "[('current_value','aaa'),('new_value','bbb'),('func','tbl_col_add')]"

        self.assertEquals(logfile[0].split("|")[9].strip(),expected_results)
        
    def tearDown(self):
        #self.log.log_clean()
        pass
Example #5
0
        _rows = self.dump(f)

        with database:
            if tbl_exists(database, self.tablename) == False:
                tbl_create(database, self.tablename, column_defn)

            try:
                tbl_rows_insert(database, self.tablename, column_names, _rows)
            except Exception, e:
                log.log(PRIORITY.FAILURE,
                        msg="timseries persistence failed in db [" +
                        database.name + "] [" + e.message + "]")
            else:
                log.log(PRIORITY.SUCCESS,
                        msg="persisted timseries in db [" + database.name +
                        "]")

    @logger(log)
    def move_files(self, download_dir, input_file_dir, prefix, moveflag=False):
        tcx_move_files = TcxMoveFiles(DOWNLOAD_DIR,
                                      INPUT_FILE_DIR,
                                      "burtnolejusa-",
                                      moveflag=moveflag)
        tcx_move_files.move_files()


class TcxMoveFiles(MoveFiles):
    def _target_conv(self, fname):
        if len(fname.split("-")) != 8:
            log.log(PRIORITY.INFO,
Example #6
0
        try:
            coldefn,values,_ = tbl_query(database,exec_str)
        except DBException, e:
            log.log(thisfuncname(),0,exception=e,msg=e.message,tblname=tblname,fldname=fldname)
    
    enums[tblname] = {}
    #name2code = dict((row[0],row[1]) for row in values)
    
    # explicit loop as OrderedDict only keeps order when items are added after initialization
    name2code = OrderedDict()
    name2enum = OrderedDict()
    code2enum = OrderedDict()
    
    for k,v,e in values:
        if v == 'None' or e == None:
            log.log(thisfuncname(),1,msg="none value detected",tblname=tblname,key=str(k))
            continue
 
        name2code[k] = v
        name2enum[k] = int(e)
        code2enum[v] = int(e)
    
    # unknown/none is represented with '??'
    name2code['??'] = '??'
        
    enums[tblname]['name2code'] = name2code
    enums[tblname]['code2name'] = dict(zip(name2code.values(),name2code.keys()))
    #enums[tblname]['name2enum'] = dict((value,enum) for enum,value in enumerate(name2code.keys()))
    #enums[tblname]['code2enum'] = dict((value,enum) for enum,value in enumerate(name2code.values()))
    
    enums[tblname]['name2enum'] =name2enum
Example #7
0
                output_row.append(" ".join(output_cell))
            else:
                output_row.append(str(item))

        outputstr += "^".join(output_row) + "\n"
    return outputstr


if __name__ == "__main__":

    enableui = True

    if len(sys.argv) <= 1:
        raise Exception("provide a database name; no extension")
    else:
        log.log(thisfuncname(), 3, msg="using database", database=sys.argv[1])

        try:
            if sys.argv[2] == "True":
                enableui = True
        except:
            pass

    of = ObjFactory(True)
    app = WizardUI(sys.argv[1],
                   of,
                   sys.argv[1],
                   maxentrycols=12,
                   maxentryrows=20)

    conflicts_only = "Y"
Example #8
0
                    tblname=tblname,
                    fldname=fldname)

    enums[tblname] = {}
    #name2code = dict((row[0],row[1]) for row in values)

    # explicit loop as OrderedDict only keeps order when items are added after initialization
    name2code = OrderedDict()
    name2enum = OrderedDict()
    code2enum = OrderedDict()

    for k, v, e in values:
        if v == 'None' or e == None:
            log.log(thisfuncname(),
                    1,
                    msg="none value detected",
                    tblname=tblname,
                    key=str(k))
            continue

        name2code[k] = v
        name2enum[k] = int(e)
        code2enum[v] = int(e)

    # unknown/none is represented with '??'
    name2code['??'] = '??'

    enums[tblname]['name2code'] = name2code
    enums[tblname]['code2name'] = dict(
        zip(name2code.values(), name2code.keys()))
    #enums[tblname]['name2enum'] = dict((value,enum) for enum,value in enumerate(name2code.keys()))
Example #9
0
                    output_cell.append(_item.replace(",","/"))    
                output_row.append(" ".join(output_cell))
            else:
                output_row.append(str(item))
        
        outputstr += "^".join(output_row) + "\n"
    return outputstr
        
if __name__ == "__main__":
    
    enableui = True
    
    if len(sys.argv) <= 1:
        raise Exception("provide a database name; no extension")
    else:
        log.log(thisfuncname(),3,msg="using database",database=sys.argv[1])
        
        try:
            if sys.argv[2] == "True":
                enableui = True
        except:
            pass

        
    of = ObjFactory(True)
    app = WizardUI(sys.argv[1],of,sys.argv[1],maxentrycols=12,maxentryrows=20)
    
    conflicts_only="Y"
    unknowns="N"
    
    if enableui == True:
Example #10
0
                    raise Exception("zero rows retreived for query [" +
                                    querystr + "]")
        except Exception, e:
            log.log(PRIORITY.FAILURE,
                    msg="failed to retrieve source data for [" + predcolname +
                    "]=[" + predvalue + "][" + e.message + "]")
            return False

        self.sourcepkcolname = pkcolname
        self.sourcevaluecolname = valuecolname
        self.sourcepredvalue = predvalue
        self.sourceid = [data[0] for data in _rows]
        self.sourcedata = [data[1] for data in _rows]

        log.log(PRIORITY.SUCCESS,
                msg="retrieved source data field [" + valuecolname +
                "] for [" + predvalue + "]")

        return True

    def get_high_value(self, ts=None):
        if ts == None:
            ts = self.sourcedata
        return max(ts)

    def get_low_value(self, ts=None):
        if ts == None:
            ts = self.sourcedata
        return min(ts)

    def get_average(self, ts=None):
        rides = cls1.get_rides(num_rides)
        cls1.download_rides(rides)

        return (cls1)

    def start_chromedriver(self):
        try:
            chromedriver = "chromedriver"
            os.environ["webdriver.chrome.driver"] = chromedriver
            self.mydriver = webdriver.Chrome(chromedriver)
        except Exception, e:
            log.log(PRIORITY.FAILURE,
                    msg="Failed to launch chromedriver [" + e.message + "]")
            raise e
        else:
            log.log(PRIORITY.SUCCESS, msg="launched chromedriver")

    def load_page(self, url):
        self.mydriver.get(url)

    def login(self, xpaths, uname, pword):
        try:
            #Clear Username TextBox if already allowed "Remember Me"
            self.mydriver.find_element_by_xpath(
                xpaths['usernameTxtBox']).clear()

            #Write Username in Username TextBox
            self.mydriver.find_element_by_xpath(
                xpaths['usernameTxtBox']).send_keys(uname)

            #Clear Password TextBox if already allowed "Remember Me"