本文整理匯總了Python中misc_utils_objectfactory.ObjFactory.object_get方法的典型用法代碼示例。如果您正苦於以下問題:Python ObjFactory.object_get方法的具體用法?Python ObjFactory.object_get怎麽用?Python ObjFactory.object_get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類misc_utils_objectfactory.ObjFactory
的用法示例。
在下文中一共展示了ObjFactory.object_get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Test_ObjFramework_Database
# 需要導入模塊: from misc_utils_objectfactory import ObjFactory [as 別名]
# 或者: from misc_utils_objectfactory.ObjFactory import object_get [as 別名]
class Test_ObjFramework_Database(unittest.TestCase):
def setUp(self):
self.of = ObjFactory(True)
self.database = Database('foobar')
self.foobar= self.of.new(dbtblgeneric,
'DBLesson',
objid='dblesson0',
constructor='datamembers',
modname=__name__,
database=self.database,
dm={'student':'booker',
'period':2,
'dow':3})
def tearDown(self):
self.of.reset()
def test_num_obj_created(self):
self.assertEquals(len(self.of.query('DBLesson')),1)
def test_correct_keys_created(self):
self.assertTrue(self.of.object_exists('DBLesson','dblesson0'))
def test_objects_created_stored(self):
_lesson = self.of.object_get('DBLesson','dblesson0')
self.assertEquals(_lesson.__class__.__name__,"DBLesson")
def test_objects_have_attributes(self):
_lesson = self.of.object_get('DBLesson','dblesson0')
self.assertEquals(_lesson.student,'booker')
self.assertEquals(_lesson.period,2)
self.assertEquals(_lesson.dow,3)
示例2: Test_addrecord
# 需要導入模塊: from misc_utils_objectfactory import ObjFactory [as 別名]
# 或者: from misc_utils_objectfactory.ObjFactory import object_get [as 別名]
class Test_addrecord(unittest.TestCase):
def setUp(self):
self.dbname='service_add_record'
self.database = Database(self.dbname)
self.of = ObjFactory(True)
self.enums = sswizard_utils.setenums(dow="all",prep=-1,database=self.database)
self.prepmap = sswizard_utils._loadprepmapper(self.database)
args = dict(database=self.database,refdatabase=self.database,saveversion=1,of=self.of,enums=self.enums)
ssviewer_utils.dataset_load(**args)
def test_(self):
# test that a new object is added into of store with the correct userobjid
expected_result = 'Stan.Math.Tuesday.830-910'
datamembers = {'student':'Nathaniel',
'teacher':'Stan',
'subject':'Math',
'period':'830-910',
'recordtype':'academic',
'dow':'Tuesday'}
args = dict(database=self.database,refdatabase=self.database,prepmap=self.prepmap,of=self.of,enums=self.enums,
datamembers=datamembers)
ssviewer_utils.dataset_add(**args)
self.assertEqual(self.of.object_get('lesson',datamembers['userobjid']).session.name,
expected_result)
def test_internal_dict(self):
# test that the internal datamembers/dm dict has the correct keys by asserting correct values
# and comparing keys vs a recovered record
expected_result = {'status': 'master', 'prep': 5, 'recordtype': 'subject',
'period': '830-910', 'substatus': 'complete', 'source': 'manual', 'session':
'Stan.Math.Tuesday.830-910', 'adult': 'Stan', 'student': 'Nathaniel', 'objtype':
'lesson', 'dow': u'TU', 'userobjid': '1.2.1.2.4', 'subject': 'Math'}
datamembers = {'student':'Nathaniel',
'teacher':'Stan',
'subject':'Math',
'period':'830-910',
'recordtype':'subject',
'dow':'Tuesday'}
args = dict(database=self.database,refdatabase=self.database,prepmap=self.prepmap,of=self.of,enums=self.enums,
datamembers=datamembers)
ssviewer_utils.dataset_add(**args)
obj_recovered = self.of.query('lesson')[0].dm.keys()
obj_add = self.of.query('lesson')[1].dm.keys()
obj_recovered.sort()
obj_add.sort()
# test keys
self.assertListEqual(obj_recovered,obj_add)
obj = self.of.object_get('lesson',datamembers['userobjid'])
obj.dm.pop("id")
# test values
self.assertEqual(obj.dm,expected_result)
def test_internal_attr(self):
# check the member attr values and that the keys are the same between recovered and added objects
datamembers = {'student':'Nathaniel',
'teacher':'Stan',
'subject':'Math',
'period':'830-910',
'recordtype':'subject',
'dow':'Tuesday'}
args = dict(database=self.database,refdatabase=self.database,prepmap=self.prepmap,of=self.of,enums=self.enums,
datamembers=datamembers)
obj = ssviewer_utils.dataset_add(**args)
self.assertEquals(obj.adult.name,'Stan')
self.assertEquals(obj.dow.name,'TU')
self.assertTrue(hasattr(obj,'id'))
self.assertEquals(obj.objtype.name,'lesson')
self.assertEquals(obj.period.name,'830-910')
self.assertEquals(obj.prep.name,5)
self.assertEquals(obj.recordtype.name,'subject')
self.assertEquals(obj.session.name,'Stan.Math.Tuesday.830-910')
self.assertEquals(obj.source.name,'manual')
self.assertEquals(obj.status.name,'master')
self.assertEquals(obj.student.name,'Nathaniel')
self.assertEquals(obj.subject.name,'Math')
self.assertEquals(obj.substatus.name,'complete')
self.assertEquals(obj.userobjid.name,'1.2.1.2.4')
#.........這裏部分代碼省略.........
示例3: SSViewer
# 需要導入模塊: from misc_utils_objectfactory import ObjFactory [as 別名]
# 或者: from misc_utils_objectfactory.ObjFactory import object_get [as 別名]
class SSViewer(object):
def __init__(self,dbname,refdbname):
log.log(thisfuncname(),3,msg="initialize",dbname=dbname,refdbname=refdbname)
self.colorpalette = dict(wp=green,subject=lightblue,ap='yellow',
Movement=pink,ELA=salmon,Humanities=lightyellow,
Counseling=lightgreen,Math=lightturquoise,
Music=lightblue,STEM=lavender,Art=purple,History=pink,
Science=darkgreen,Core=karky,Chess=burgundy,
computertime='darkgrey',Speech=darkburgundy,
Student_News=darkgrey,Computer_Time=brown,
Activity_Period=mauve,Melissa=navyblue,Amelia=darkgreen,
Samantha=darkyellow, Alexa=paleblue, Paraic=palegreen,
Francisco=cerise,Rahul=verydarkgrey,Dylan=verydarkgrey,
Moira=verydarkgrey,Issey=verydarkgrey, Daryl=verydarkgrey,
Karolina=verydarkgrey)
self.fontpalette = dict(Amelia=green,Paraic=darkgreen,Stan=lavender,
Samantha=lightgreen,Alexa=blue,Francisco=purple,
Melissa=lightblue,Rahul=dirtyyellow,Dylan=dirtyyellow,
Moira=dirtyyellow,Issey=dirtyyellow, Daryl=dirtyyellow,
Karolina=dirtyyellow,Chess=pink,Student_News=lightyellow,
subject=blue)
self.of = ObjFactory(True)
self.refdatabase = Database(refdbname)
self.dbname = dbname
self.database = Database(self.dbname)
self.lastsaveversion=0
def _color_get_multi(self,values):
bgs=[]
fgs=[]
for value in values:
_bg,_fg = self.color_get(value)
bgs.append(_bg)
fgs.append(_fg)
return(bgs,fgs)
def color_get(self,value):
bg = lightgrey
fg = black
try:
int(value)
value = str(value)
except ValueError:
pass
if value.count(" ") > 0:
value= value.replace(" ","_")
if value.count("[") == 1 and value.count("]") == 1:
bg = red
if value.count(".") > 0:
value = value.split(".")[0]
if self.colorpalette.has_key(value):
bg = self.colorpalette[value]
if self.fontpalette.has_key(value):
fg = self.fontpalette[value]
return(bg,fg)
def viewer(self,yaxis_type,xaxis_type,ztypes, source_type,source_value,
conflicts_only='N',constraints=None,wratio=None,formatson=False):
if source_value == "":
source_objs = self.of.query(source_type)
else:
source_objs = [self.of.object_get(source_type,source_value)]
xaxis_obj = self.of.query(xaxis_type)
yaxis_obj = self.of.query(yaxis_type)
count=0
yaxis_enum = {}
for _yaxis_obj in yaxis_obj:
yaxis_enum[_yaxis_obj.name] = count
count+=1
xaxis_enum = self.enums[xaxis_type]['name2enum']
values = [] # contains the values displayed on the grid
values = [['']]
for yval in yaxis_enum.keys():
values[0].append(yval)
for xval in xaxis_enum.keys():
values.append([xval])
#.........這裏部分代碼省略.........