本文整理汇总了Python中misc_utils_objectfactory.ObjFactory.new方法的典型用法代码示例。如果您正苦于以下问题:Python ObjFactory.new方法的具体用法?Python ObjFactory.new怎么用?Python ObjFactory.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类misc_utils_objectfactory.ObjFactory
的用法示例。
在下文中一共展示了ObjFactory.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test_ObjFramework_2_records_same_cls
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFramework_2_records_same_cls(unittest.TestCase):
def setUp(self):
self.of = ObjFactory()
self.obj1= self.of.new(GenericBase,
'Student',
objid='booker',
modname=__name__,
name='booker',
age=23)
self.obj2= self.of.new(GenericBase,
'Student',
objid='frank',
modname=__name__,
name='frank',
age=19)
def tearDown(self):
self.of.reset()
def test_2records_same_class(self):
names = [obj.name for obj in self.of.query('Student')]
names.sort()
self.assertEquals(names,['booker','frank'])
示例2: Test_ObjFrameworkDumpRptNestedSchoolschedFieldNameHdr
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFrameworkDumpRptNestedSchoolschedFieldNameHdr(unittest.TestCase):
# same as above just with the school sched nested object
# so each attr is another object of (not a string or int) that
# potentially needs to be accessed via accessors
def setUp(self):
self.of = ObjFactory(True)
self.database = Database('foobar')
datamembers = dict(period='830-910',student='Booker',dow='MO',
teacher='Amelia',saveversion=0,session='AM.AC.SC')
self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson0',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers)
datamembers = dict(period='910-950',student='Booker',dow='MO',
teacher='Stan',saveversion=0,session='AM.AC.SC')
self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson1',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers)
datamembers = dict(period='950-1020',student='Booker',dow='MO',
teacher='Samantha',saveversion=0,session='AM.AC.SC')
self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson2',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers)
datamembers = dict(period='830-910',student='Clayton',dow='MO',
teacher='Samantha',saveversion=0,session='AM.AC.SC')
self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson3',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers)
def test_1constraint(self):
from types import StringType,IntType, UnicodeType
expected_results = [['ROOT', 'student:Booker', 'period:830-910', 'objtype:DBLesson'],
['ROOT', 'student:Clayton', 'period:830-910', 'objtype:DBLesson']]
results = self.of.dumpobjrpt(objtypes=['DBLesson'],
objref=False,
fields=['student','period'],
omitfields=['id'],
fieldnames=True)
expected_results.sort()
results.sort()
self.assertListEqual(expected_results,results)
self.assertListEqual(expected_results,results)
示例3: Test_ObjFramework_Database
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [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)
示例4: Test_ObjFrameworkDumpRpt
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFrameworkDumpRpt(unittest.TestCase):
def setUp(self):
self.of = ObjFactory(True)
self.obj1 = self.of.new(GenericBase,
'Student',
objid='booker',
nationality='british',
modname=__name__)
def test_no_datafields(self):
from types import StringType,IntType, UnicodeType
expected_results = [['ROOT', 'Student']]
results = self.of.dumpobjrpt(objref=False)
expected_results.sort()
results.sort()
self.assertListEqual(expected_results,results)
def test_inc_datafields(self):
from types import StringType,IntType, UnicodeType
expected_results = [['ROOT', 'british', 'Student']]
results = self.of.dumpobjrpt(fields=['nationality'],objref=False)
expected_results.sort()
results.sort()
self.assertListEqual(expected_results,results)
示例5: Test_ObjFrameworkBasic
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFrameworkBasic(unittest.TestCase):
def setUp(self):
self.of = ObjFactory()
foobar= self.of.new(GenericBase,
"Student",
objid='booker',
modname=__name__,
name='booker',
age=23)
def tearDown(self):
self.of.reset()
def test_num_obj_created(self):
self.assertEquals(len(ObjFactory().store['Student']),1)
def test_correct_keys_created(self):
self.assertTrue(ObjFactory().store['Student'].has_key('booker'))
def test_objects_created_stored(self):
_student = ObjFactory().store['Student']['booker']
self.assertEquals(_student.__class__.__name__,"Student")
def test_objects_have_attributes(self):
_student = ObjFactory().store['Student']['booker']
self.assertEquals(_student.name,'booker')
self.assertEquals(_student.age,23)
示例6: Test_ObjFramework_Database_Derived_DB
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFramework_Database_Derived_DB(unittest.TestCase):
def setUp(self):
self.of = ObjFactory(True)
self.database = Database('foobar')
datamembers = dict(period='830',
student='Booker',
teacher='Amelia',
saveversion=0,
session='AM.AC.SC')
self.foobar= self.of.new(schoolschedgeneric,
'DBLesson',
objid='dblesson0',
constructor='datamembers',
database=self.database,
of=self.of,
modname=__name__,
dm=datamembers)
self.foobar.keepversion = True
def test_persist(self):
with self.database:
self.foobar.persist()
self.database = Database('foobar',True)
with self.database:
col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['student','teacher'])
self.assertEquals([['Booker','Amelia']],tbl_rows)
def test_persist_customtimestamp(self):
self.foobar.customtimestamp = "%y%m%d_%H%M%S"
with self.database:
self.foobar.persist()
self.database = Database('foobar',True)
with self.database:
col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['__timestamp'])
self.assertTrue(13,len(tbl_rows[0][0]))
def test_update_1field(self):
expected_results = [[u'830', u'AM.AC.SC', u'Booker', u'Amelia', u'version'],
[u'830', u'AM.AC.SC', u'Booker', u'Aaron', u'current']]
self.foobar.customtimestamp = "%y%m%d_%H%M%S"
with self.database:
self.foobar.persist()
self.foobar.update('teacher',"\"Aaron\"")
self.database = Database('foobar',True)
with self.database:
col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['period','session','student','teacher','__version'] )
self.assertListEqual(tbl_rows,expected_results)
示例7: Test_ObjFrameworkGetByVal
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFrameworkGetByVal(unittest.TestCase):
# test we can find an return an object given the type and the value
def setUp(self):
self.of = ObjFactory(True)
self.database = Database('foobar')
datamembers = dict(period='830',
student='Booker',
dow='MO',
teacher='Amelia',
saveversion=0,
session='AM.AC.SC')
self.foobar= self.of.new(schoolschedgeneric,
'DBLesson',
objid='dblesson0',
constructor='datamembers',
database=self.database,
of=self.of,
modname=__name__,
dm=datamembers)
datamembers = dict(period='910',
student='Clayton',
dow='TU',
teacher='Stan',
saveversion=0,
session='ST.AC.SC')
self.foobar= self.of.new(schoolschedgeneric,
'DBLesson',
objid='dblesson1',
constructor='datamembers',
database=self.database,
of=self.of,
modname=__name__,
dm=datamembers)
def test_(self):
self.assertEquals(self.of.object_get_byval("period","830").name,"830")
self.assertEquals(self.of.object_get_byval("period","910").name,"910")
self.assertEquals(self.of.object_get_byval("period","foobar"),None)
示例8: Test_ObjFrameworkDupeID
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFrameworkDupeID(unittest.TestCase):
def setUp(self):
self.of = ObjFactory()
self.obj1= self.of.new(GenericBase,
'Student',
objid='booker',
modname=__name__)
self.obj2= self.of.new(GenericBase,
'Student',
objid='booker',
modname=__name__)
def tearDown(self):
self.of.reset()
def test_num_dupe_objid(self):
self.assertEqual(self.obj1,self.obj2)
示例9: Test_ObjFrameworkDumpNested
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFrameworkDumpNested(unittest.TestCase):
def setUp(self):
self.of = ObjFactory(True)
self.obj1 = self.of.new(GenericBase,
'Student',
objid='booker',
nationality='british',
modname=__name__)
self.of.new(GenericBase,
'Student',
objid='fred',
age=23,
nationality='british',
modname=__name__)
self.of.new(GenericBase,
'Student',
objid='fred',
age=35,
nationality='irish',
modname=__name__)
self.of.new(GenericBase,
'Classroom',
objid='1a',
nationality='swedish',
modname=__name__)
def tearDown(self):
self.of.reset()
'''def test_1clause(self):
results = self.of.query_advanced('Student',[('objid','booker')])
self.assertEquals(len(results),1)
self.assertEquals(results[0].objid,'booker')
def test_2clause(self):
results = self.of.query_advanced('Student',[('nationality','british'),
('objid','fred')])
self.assertEquals(len(results),1)
self.assertEquals(results[0].age,23)'''
def test_update_then_search(self):
''' make sure that search picks up the updated version of the object '''
self.obj1.nationality = 'indian'
results = self.of.query_advanced('Student',[('objid','booker')])
self.assertEquals(results[0].nationality,'indian')
示例10: Test_ObjFrameworkIter
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFrameworkIter(unittest.TestCase):
def setUp(self):
self.of = ObjFactory(True)
self.of.new(GenericBase,
'Student',
objid='booker',
modname=__name__)
self.of.new(GenericBase,
'Student',
objid='fred',
modname=__name__)
self.of.new(GenericBase,
'Classroom',
objid='1a',
modname=__name__)
def tearDown(self):
self.of.reset()
def test_iter(self):
result = [obj.objid for obj in self.of.object_iter()]
result.sort()
self.assertListEqual(result,['1a','booker','fred'])
示例11: Test_ObjFramework_2_class
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFramework_2_class(unittest.TestCase):
def setUp(self):
self.of = ObjFactory()
self.obj1= self.of.new(GenericBase,
'Student',
objid='booker',
modname=__name__,
name='booker',
age=23)
self.obj2= self.of.new(GenericBase,
'Subject',
objid='science',
modname=__name__,
name='science',
teacher_name='fran')
def tearDown(self):
self.of.reset()
def test_2_class(self):
self.assertListEqual(self.of.query(),['Student','Subject'])
示例12: Test_ObjFramework_Database_Derived_Nested_DupeKey
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFramework_Database_Derived_Nested_DupeKey(unittest.TestCase):
def setUp(self):
self.of = ObjFactory(True)
self.database = Database('foobar')
self.datamembers = dict(period='830',
student='Booker',
teacher='Amelia',
saveversion=0,
session='AM.AC.SC')
def test_student_objid(self):
obj1 = self.of.new(schoolschedgeneric,
'DBLesson',
objid='dblesson0',
constructor='datamembers',
database=self.database,
of=self.of,
modname=__name__,
dm=self.datamembers)
obj2 = self.of.new(schoolschedgeneric,
'DBLesson',
objid='dblesson0',
constructor='datamembers',
database=self.database,
of=self.of,
modname=__name__,
dm=self.datamembers)
#print self.of.store['student']
#print obj1.student,obj2.student
self.assertEqual(str(obj1.student),str(obj2.student))
示例13: Test_ObjFramework_Database_Derived_Nested
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFramework_Database_Derived_Nested(unittest.TestCase):
def setUp(self):
self.of = ObjFactory(True)
self.database = Database('foobar')
datamembers = dict(period='830',
student='Booker',
teacher='Amelia',
saveversion=0,
session='AM.AC.SC')
self.foobar= self.of.new(schoolschedgeneric,
'DBLesson',
objid='dblesson0',
constructor='datamembers',
database=self.database,
of=self.of,
modname=__name__,
dm=datamembers)
def test_student_objid(self):
obj = self.of.store['student']['Booker']
attr = obj.attr_get_keyval(include_callable=False,
include_baseattr=True,
include_nondataattr=True)
d = dict(attr)
self.assertTrue(d.has_key('objid'))
self.assertEqual(d['objid'],'Booker')
def test_student_name(self):
obj = self.of.store['student']['Booker']
attr = obj.attr_get_keyval(include_callable=False,
include_baseattr=True,
include_nondataattr=True)
d = dict(attr)
self.assertTrue(d.has_key('name'))
self.assertEqual(d['name'],'Booker')
示例14: Test_ObjFramework_Database_Derived
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFramework_Database_Derived(unittest.TestCase):
# pass in a subclass of dbtblgeneric as a baseclass; testing a bug found
# in schoolschedulewizard
class Dummy(dbtblgeneric):
pass
def setUp(self):
self.of = ObjFactory(True)
self.database = Database('foobar')
self.foobar= self.of.new(self.Dummy,
'DBLesson',
objid='dblesson0',
constructor='datamembers',
modname=__name__,
database=self.database,
dm={'student':'booker',
'period':2,
'dow':3})
def test_num_obj_created(self):
self.assertEquals(len(self.of.query('DBLesson')),1)
示例15: Test_ObjFrameworkDump
# 需要导入模块: from misc_utils_objectfactory import ObjFactory [as 别名]
# 或者: from misc_utils_objectfactory.ObjFactory import new [as 别名]
class Test_ObjFrameworkDump(unittest.TestCase):
def setUp(self):
self.of = ObjFactory(True)
self.obj1 = self.of.new(GenericBase,
'Student',
objid='booker',
nationality='british',
modname=__name__)
def test_(self):
from types import StringType,IntType, UnicodeType
expected_results = [[('pobjid', 'ROOT'),('objid', 'booker'), ('objtype', 'Student'), ('nationality', 'british')]]
_results = self.of.dumpobj()
results = []
for result in _results:
result.pop('id')
results.append([(k,v) for k,v in result.iteritems() if type(v) in [IntType,StringType,UnicodeType]])
expected_results.sort()
results.sort()
self.assertListEqual(expected_results,results)