def test_overriding(self): """This verifies that child classes still can find the correct stack traces https://github.com/Jaymon/pout/issues/8 """ original_class = pout.V_CLASS class Child(original_class): def full_value(self): call_info = self.reflect.info if call_info["args"][0]["val"] == "foo": return self._printstr(["foo custom "], call_info) else: return super(Child, self).full_value() pout.V_CLASS = Child try: # v = "foo" # pout.v(v) # return with testdata.capture() as c: v = "foo" pout.v(v) self.assertTrue("foo custom" in c) with testdata.capture() as c: v = "bar" pout.v(v) self.assertTrue('"bar"' in c) finally: pout.V_CLASS = original_class
def test_keys(self): d = {'\xef\xbb\xbffoo': ''} d = {'\xef\xbb\xbffo_timestamp': ''} pout.v(d) d = {0: "foo", 1: "bar"} pout.v(d)
def __init__(self, query, data=None, sql_file=None, dbtype='sqlite3', debug=False): self.dbtype = dbtype self.query = query self.data = data self.sql_file = sql_file if self.sql_file is None: tablename = self.GetTableName( self.query) # re.sub('^.+FROM.([a-zA-Z]+)', '\\1', query) self.sql_file = GetSQLFile(tablename).Get() pout.v(self.sql_file) self.debug = debug checkTypes = [] # if query is not None: # query = query.replace("?","%s") checkTypes = [('query', self.query), ('data', self.data)] self.query = query self.data = self.MaskData(query, data) returnd = None
def DescribeTable(self): if self.dbtype == 'mysql': query = '''SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'rhp' AND TABLE_NAME = "{}" AND COLUMN_NAME = "{}"'''.format(self.table) if self.dbtype == 'sqlite3': query = '.schema {}'.format(self.table) data = [] returnd = DBConnect(query, data, sql_file=self.sql_file).ALL() pout.b(f'DescribeTable : {query} \nReturnd : {returnd}') info = {} tb = len(returnd) for cnt in range(0, tb): for val in returnd: pout.v(f'Val : {val}') info[cnt] = { 'field': val[2], 'type': val[7], 'null': val[6], 'key': val[16], 'default': val[5], 'extra': val[17] } returnd = info pout.v(returnd) time.sleep(3) # except: # returnd = None return returnd
def test_binary_unicode_error(self): d = hmac.new(b"this is the key", b"this is the message", hashlib.md5) with testdata.capture() as c: pout.v(d.digest()) self.assertTrue("d.digest()" in c) self.assertTrue(" b'" in c) self.assertFalse(" b''" in c)
def test_set(self): s = set(["foo", "bar", "che"]) with testdata.capture() as c: pout.v(s) for s in ['"foo"', '"che"', '"bar"', "s (3) =", "{", "}"]: self.assertTrue(s in c, s)
def QueryCheck(self, fromTable, queryWhere=None, queryData=None, debug=False): pout.v(fromTable) if queryWhere == '' or queryWhere is None: query = 'SELECT count(*) FROM {0}'.format(fromTable) data = '' elif not re.search('(=|LIKE)', queryWhere) and queryWhere.count('?') == 0: query = '''SELECT count(*) FROM {0} WHERE {1}=(?)'''.format(fromTable, queryWhere) data = queryData else: query = '''SELECT count(*) FROM {0} WHERE {1}'''.format(fromTable, queryWhere) data = queryData #VarOps().GetTyped(fromTable) returnd = SQConnect(query, data).ONE() if re.search('(list|tuple)', str(type(returnd)), re.I): returnd = VarOps().DeTupler(returnd) return returnd
def test_str(self): ''' since -- 3-28-2013 ''' s_unicode = "this is a unicode string" s_byte = b"this is a byte string" with testdata.capture() as c: pout.v(s_unicode) pout.v(s_byte) self.assertTrue("b'this is a byte string'" in c.stderr) self.assertTrue('"this is a unicode string"' in c.stderr) s_unicode = "" s_byte = b"" with testdata.capture() as c: pout.v(s_unicode) pout.v(s_byte) self.assertTrue("b''" in c.stderr) self.assertTrue('""' in c.stderr) #print(c.stderr.read()) d = { 'foo': "foo is a unicode str", 'bar': b"bar is a byte string" } with testdata.capture() as c: pout.v(d) self.assertTrue('\'foo\': "foo is a unicode str"' in c.stderr) self.assertTrue("'bar': b'bar is a byte string'" in c.stderr)
def ONE(self): if self.dbtype == 'mysql': con = pymysql.connect(host='localhost', user='******', passwd='password', db='rhp') if self.dbtype == 'fdb': con = fdb.connect(host='localhost', database=f'{self.sql_file}', user='******', password='******') if self.dbtype == 'sqlite3': pout.v(self.sql_file) con = sqlite3.connect(self.sql_file) # con.row_factory = sqlite3.Row cur = con.cursor() if len(self.data) > 0: cur.execute(self.query, self.data) else: cur.execute(self.query) returnd = cur.fetchone() pout.v(returnd) #print(returnd[0]) pout.b('--') # if self.dbtype == 'sqlite3': # returnd = [{k: item[k] for k in item.keys()} for item in returnd] if re.search('(UPDATE|INSERT)', self.query, re.I): con.commit() con.close() return returnd
def test_exception(self): try: f = Foo() f.raise_error() except Exception as e: pout.v(e)
def SetCtrl(self, value): if value is None: value = '' pout.v(value) a = self.CheckSaveLoadAs(value, 'load') pout.v(a) self.SetValue(a)
def onLoad(self, event): storeNum = self.storenum_tc.GetValue() listd = self.LSL.To_Dict() print(listd) q, d, sqlfile = self.LSL.GetSelectQD( listd['basic_store_info']['selects']) r = SQConnect(q, d, sqlfile).ONE() for key in listd: # selects = ','.join(listd[key]['selects']) # q = f'SELECT {selects} FROM {key}' # d = () print(q, d, sqlfile) r = SQConnect(q, d, sqlfile).ONE() idx = 0 for i in listd[key]['selects']: listd[key][i].update({'set': r[idx]}) idx += 1 pout.v(listd) for i in listd[key]: print(f'listd[{key}][{i}]') if not 'selects' in i: setItem = listd[key][i]['set'] objItem = listd[key][i]['obj'] objItem.SetCtrl(setItem)
def __new__(cls, *args, **kwargs): pout.v("__new__", args, kwargs) #frame = inspect.currentframe() #frames = inspect.getouterframes(frame) #pout.v(frame, frames) return super(Dec, cls).__new__(cls)
def OnSave(self, whereField, whereValue): a = self.GetLabel() try: returnd = LookupDB(self.tableName).UpdateSingle( self.fieldName, a, whereField, whereValue) except: pout.v( f'Table : {self.tableName} ; Field : {self.fieldName} ; WhereField : {whereField} ; whereValue: {whereValue}' )
def test_multiline_comma(self): # https://github.com/Jaymon/pout/issues/12 with testdata.capture() as c: pout.v( "foo", "bar", "che", ) self.assertTrue('"foo"\n\n"bar"\n\n"che"' in c)
def __get__(self, instance, klass): """ having this method here turns the class into a descriptor used when there is no (...) on the decorator """ pout.v("__get__") def wrapper(*args, **kwargs): return "__get__" return wrapper
def OnLoad(self, whereField, whereValue): returnd = LookupDB(self.tableName).Specific(whereValue, whereField, self.fieldName) try: jsond = json.loads(returnd) self.SetObjects(jsond) except: print('returnd Not JSON\'d') pout.v(jsond)
def OnSave(self, whereField, whereValue): a = self.GetValue() date_str = a.strftime('%d-%m-%Y %H:%M:%S') try: returnd = LookupDB(self.tableName).UpdateSingle( self.fieldName, b, whereField, whereValue) except: pout.v( f'Table : {self.tableName} ; Field : {self.fieldName} ; WhereField : {whereField} ; whereValue: {whereValue}' )
def OnLoad(self, whereField, whereValue): returnd = LookupDB(self.tableName).Specific(whereValue, whereField, self.fieldName) a = VarOps().GetTyped(returnd) pout.v(f'OnLoad Time Returnd : {returnd}') if returnd is None: returnd = datetime.datetime.strptime('01/01/1969', '%m/%d/%Y') date_obj = datetime.datetime.strptime(returnd, '%d-%m-%Y %H:%M:%S') self.SetValue(returnd)
def test_object_pout_method(self): class PoutFoo(object): bar = "bar" def __pout__(self): return { "bar": "pout bar" } instance = PoutFoo() pout.v(instance)
def CheckJson(self, myjson): posttype = self.CheckType(myjson) pout.v(f'Check Type : {posttype}') try: json_object = json.loads(posttype) except: json_object = posttype pout.v(json_object) return json_object
def OnSave(self, whereField, whereValue): a = self.GetValue() b = VarOps().DoJson(a) try: returnd = LookupDB(self.tableName).UpdateSingle( self.fieldName, b, whereField, whereValue) except: pout.v( f'Table : {self.tableName} ; Field : {self.fieldName} ; WhereField : {whereField} ; whereValue: {whereValue}' )
def OnSave(self, whereField, whereValue): setTo = self.GetPath() pout.b(f'WhereField : {whereField} --> WhereValue : {whereValue}') pout.v(f'tableName : {self.tableName} ; fieldName : {self.fieldName}') try: item = LookupDB(self.tableName).UpdateSingle( self.fieldName, setTo, whereField, whereValue) except: pout.v( f'Table : {self.tableName} ; Field : {self.fieldName} ; WhereField : {whereField} ; whereValue: {whereValue}' )
def __call__(self, *args, **kwargs): """call is used when there are (...) on the decorator""" pout.v("__call__", args, kwargs) #pout.v(vars(self)) #frame = inspect.currentframe() #frames = inspect.getouterframes(frame) #pout.v(frames[1:]) def wrapper(*args, **kwargs): return "__call__" return wrapper
def OnSave(self, whereField, whereValue): b = self.GetObjects() jsond = json.dumps(b) pout.v(f'GetSelectedObjects : {b}') try: returnd = LookupDB(self.tableName).UpdateSingle( self.fieldname, jsond, whereField, whereValue) except: pout.v( f'Table : {self.tableName} ; Field : {self.fieldName} ; WhereField : {whereField} ; whereValue: {whereValue}' )
def test_sys_module(self): ''' built-in modules fail, which they shouldn't since -- 7-19-12 ''' with testdata.capture() as c: pout.v(sys) for s in ["sys = sys module", "Functions:", "Classes:"]: self.assertTrue(s in c, "[{}] is not present".format(s))
def JSONtoGRID(self, JSONFile): dictd = json.loads(JSONFile) x = 0 y = 0 for x in range(xcnt): rowLabel = self.grid.GetRowLabelValue() for y in range(ycnt): colLabel = self.grid.GetColLabelValue() celldata = dictd[rowLabel][colLabel] pout.v( f'Row : {rowLabel} ; Col : {colLabel} ; Data : {celldata}') self.grid.SetCellValue(x, y, celldata)
def OnLoad(self, whereField, whereValue): returnd = LookupDB(self.tableName).Specific(whereValue, whereField, self.fieldName) a = VarOps().GetTyped(returnd) if 'tuple' in a: returnd = returnd[0] if returnd is None: returnd = '' try: self.SetLabel(returnd) except TypeError as e: pout.v(e)
def onLoad(self, event): lc_name = 'invMaint_priceSchemes_listctrl' listctrl = wx.FindWindowByName(lc_name) query = 'SELECT scheme_list, reduce_by, name FROM item_pricing_schemes' data = '' pout.v(query) returnd = SQConnect(query, data).ALL() idx = 0 for scheme_list, reduceby, named in returnd: setList = [(0, named), (1, scheme_list), (2, str(reduceby))] ListCtrl_Ops(lc_name).LCFill(setList, idx)
def is_field(self, fieldname): query = ''' SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'rhp' AND TABLE_NAME = '{}' AND COLUMN_NAME = '{}'; '''.format(self.table, fieldname) data = [] returnd = DBConnect(query, data, sql_file=self.sql_file).ONE() pout.v(query) return returnd
def test_issue_34(self): """https://github.com/Jaymon/pout/issues/34""" class FooIssue34(object): bar_che = ["one", "two", "three"] left = "left" right = "right" with testdata.capture() as c: pout.v(left, " ".join(FooIssue34.bar_che), right) self.assertTrue("right" in c) self.assertTrue("left" in c) self.assertTrue("one two three" in c)
def test_issue_31(self): """https://github.com/Jaymon/pout/issues/31""" class Issue31String(String): def bar(self): pout.h() return "" with testdata.capture() as c: s = Issue31String("foo") pout.v(s.bar()) lines = re.findall(r"\([^:)]+:\d+\)", str(c)) self.assertEqual(2, len(lines)) self.assertNotEqual(lines[0], lines[1])
def FormatPhoneNumber(self, event): obj = event.GetEventObject() val = obj.GetValue().strip() if len(val) == 3: pout.v(len(val)) new_val = f'({val})' print(f"new_val = '({val})'") elif len(val) == 6: pout.v(len(val)) new_val = f'({val[1]}{val[2]}{val[3]}) {val[5]}' print(f"new_val = '({val[1]}{val[2]}{val[3]}) {val[5]}'") elif len(val) == 10: pout.v(len(val)) new_val = f'({val[1]}{val[2]}{val[3]}) {val[6]}{val[7]}{val[8]}-{val[9]}' print( f"new_val = '({val[1]}{val[2]}{val[3]}) {val[6]}{val[7]}{val[8]}-{val[9]}'" ) elif not re.search('([0-9]|\-.|\(.|\(\)|\).)', val): new_val = '' else: pout.v(len(val)) new_val = val print(f"new_val = {val}") obj.ChangeValue(new_val) obj.SetInsertionPointEnd()
def OnSave(self, whereField, whereValue): a = self.GetValue() if a is True: a = 1 if a is False: a = 0 try: returnd = LookupDB(self.tableName).UpdateSingle( self.fieldName, a, whereField, whereValue) except: pout.v( f'Table : {self.tableName} ; Field : {self.fieldName} ; WhereField : {whereField} ; whereValue: {whereValue}' )
def is_table(self): pout.v(self.dbtype) if self.dbtype == 'mysql': query = '''SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'rhp' AND TABLE_NAME = "{}" '''.format(self.table) if self.dbtype == 'sqlite3': query = '.schema {}'.format(self.table) data = [] returnd = DBConnect(query, data, sql_file=self.sql_file).ALL() return returnd
def test_get_name(self): """makes sure if __getattr__ raises other errors than AttributeError then pout will still print correctly""" class FooGetName(object): def __init__(self): self.fields = {} def __getattr__(self, key): # This will raise a KeyError when key doesn't exist return self.fields[key] with testdata.capture() as c: fgn = FooGetName() pout.v(fgn) for s in ["interface_test.FooGetName", "id:", "path:", "Ancestry:", "__str__:", "fields = "]: self.assertTrue(s in c, s)
def CheckType(self, ret): if ',' in self.query: ret = ret[0] else: while 'tuple' in self.Typd(ret): # if len(ret) == 0 and not 'tuple' in self.Typd(ret): # pout.v('Len of ret : {}'.format(len(ret))) # break try: ret = ret[0] except IndexError as e: print(f'Returnd : {ret} ; {e}') break pout.v(f'CheckType : {ret}') return ret
def test_misclassified_instance(self): """objects that have a __getattr__ method that always return something get misclassified as dict proxies, this makes sure that is fixed""" def misclass_func(): return 2 class Misclass(object): def __getattr__(self, k): return 1 with testdata.capture() as c: m = Misclass() pout.v(m) self.assertTrue("interface_test.1 instance" in c) self.assertTrue("m = " in c)
def CheckSaveLoadAs(self, value, typd): conv = self.loadAs if typd == 'save': conv = self.saveAs pout.v('CheckSaveLoadAs : ', value, self.loadAs) if 'str' in conv: value = str(value) elif 'int' in conv: value = int(value) elif 'float' in conv: value = float(value) elif 'decimal' in conv: value = Decimal(value) return value
def OnLoad(self, whereField, whereValue): returnd = LookupDB(self.tableName).Specific(whereValue, whereField, self.fieldName) pout.v(returnd[0]) jsond = VarOps().CheckJson(returnd[0]) pout.v(returnd) pout.v(returnd[0]) j = json.loads(returnd) pout.v(f'RH_LoadSaveListBox : {j}') if jsond is not False: self.AppendItems(j)
def test_type(self): with testdata.capture() as c: pout.v(type(100)) pout.v(str(c)) self.assertTrue("type(100) =" in c) self.assertTrue("'int'" in c) with testdata.capture() as c: pout.v(type([])) self.assertTrue("type([]) =" in c) self.assertTrue("'list'" in c)
def OnSave(self, whereField, whereValue): a = self.GetValue() pout.v(f'Date Picker Ctrl : {a}') b = a.FormatISODate() pout.v(f'Date Picker Crtl ISO Date : {b}') try: returnd = LookupDB(self.tableName).UpdateSingle( self.fieldName, b, whereField, whereValue) except: pout.v( f'Table : {self.tableName} ; Field : {self.fieldName} ; WhereField : {whereField} ; whereValue: {whereValue}' )
def test_precision(self): """float precision was cutting off at 2 decimal places""" with testdata.capture() as c: f = 1380142261.454746 pout.v(f) self.assertTrue(str(f) in c) with testdata.capture() as c: i = 1232432435 pout.v(i) self.assertTrue(str(i) in c) with testdata.capture() as c: b = True pout.v(b) self.assertTrue("b = True" in c)
def test_binary_1(self): with testdata.capture() as c: v = memoryview(b'abcefg') pout.v(v) v = bytearray.fromhex('2Ef0 F1f2 ') pout.v(v) if is_py2: v = bytes("foobar") else: v = bytes("foobar", "utf-8") pout.v(v) if is_py2: # memoryview just gives a reference in py2 # bytearray is also different but I don't care enough to fix it for s in ["b'foobar'", "b'.\uFFFD\uFFFD\uFFFD'"]: self.assertTrue(s in c, s) else: for s in ["b'abcefg'", "b'foobar'", "b'.\\xf0\\xf1\\xf2'"]: self.assertTrue(s in c, s)
def DefaultChoices(self): returnd = LookupDB(self.DefTable).General(self.DefField) try: self.listd = returnd[0] except: pout.v(returnd)
def test_object_ancestry(self): f = Foo3() pout.v(f)
def test_really_long_list(self): raise unittest.SkipTest("This takes about 14 seconds to run") v = [testdata.get_words(1) for x in range(260818)] pout.v(v)
username = '******' password = '******' server = jenkins.Jenkins('http://ci-bit/', username='******', password='******') # https://python-jenkins.readthedocs.io/en/latest/api.html user = server.get_whoami() version = server.get_version() print('Hello %s from Jenkins %s' % (user['fullName'], version)) print(server.jobs_count()) jobs = server.get_jobs() pout.v(jobs) # # print(server.get_job("aky-be-pipeline-prod").get_last_buildnumber()) last_build_number = server.get_job_info( 'aky-be-pipeline-prod')['lastCompletedBuild']['name'] print(last_build_number) #build_info = server.get_build_info('aky-be-pipeline-prod', last_build_number) #build_info def b_time(): for key, job in server.iteritems(): build_time(job) return (0)
def test_range_iterator(self): #p = pout.Pout() #print(p._get_type(range(5))) with testdata.capture() as c: pout.v(range(5)) self.assertTrue("range(5) (5) = " in c)
def test_not_in_val(self): with testdata.capture() as c: sentinal = "foo" val = "foobar" pout.v(sentinal not in val) self.assertTrue("sentinal not in val" in c)
def test_queue(self): """Queue.Queue was failing, let's fix that""" pout.v(queue.Queue)
def test_multiline_call(self): foo = 1 bar = 2 from pout import v as voom with testdata.capture() as c: voom( foo,bar ) self.assertTrue("foo = 1\n\nbar = 2" in c) with testdata.capture() as c: pout.v( foo, bar, "this is a string" ) self.assertTrue("foo = 1\n\nbar = 2\n\n\"this is a string\"" in c) from pout import v with testdata.capture() as c: v( foo, bar) self.assertTrue("foo = 1\n\nbar = 2" in c) with testdata.capture() as c: v( foo, bar) self.assertTrue("foo = 1\n\nbar = 2" in c) with testdata.capture() as c: v( foo, bar ) self.assertTrue("foo = 1\n\nbar = 2" in c) def func(a, b): return a + b with testdata.capture() as c: v( func(1, 4) ) self.assertTrue("func(1, 4) = 5" in c) with testdata.capture() as c: v( func( 5, 5 ) ) self.assertTrue("= 10" in c) import pout as poom with testdata.capture() as c: poom.v(foo) self.assertTrue("foo = 1" in c)
def test_instance_str_method(self): b = Bar() pout.v(b)
def test_one_arg(self): foo = [ [ [1, 2, 3], ], [ [5, 6, 7], ], ] #foo = [range(1, 3) for x in (range(1, 2) for x in range(1))] pout.v(foo) foo = 1 bar = 2 pout.v(foo) pout.v(foo, bar) foo = "this is a string" pout.v(foo) foo = True pout.v(foo) foo = [] pout.v(foo) foo = list(range(1, 10)) pout.v(foo) foo = [list(range(1, 10)) for x in list(range(2))] pout.v(foo) foo = {} pout.v(foo) foo = {'foo': 1} pout.v(foo)
def Show(self): pout.v(self.listd)
def __init__(self, tname='POS', debug=False): self.tname = self.GetThemeName(tname) pout.v(self.tname)
def test_module(self): pout.v(pout) pout.v(sys.modules[__name__])
def test_object_2(self): b = Bam() pout.v(b)
def test_object(self): f = Foo() pout.v(f) c = Che() pout.v(c)