当前位置: 首页>>代码示例>>Python>>正文


Python Db.setup方法代码示例

本文整理汇总了Python中db.Db.setup方法的典型用法代码示例。如果您正苦于以下问题:Python Db.setup方法的具体用法?Python Db.setup怎么用?Python Db.setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在db.Db的用法示例。


在下文中一共展示了Db.setup方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_insert_row_when_add_new_word_list

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
 def test_insert_row_when_add_new_word_list(self):
     db = Db(self.conn, self.sql)
     db.setup(3)
     word_list = ['one', 'two', 'three']
     db.add_word(word_list)
     
     execute_args = self.conn.stub_cursor.execute_args
     self.assertEqual(len(execute_args), 6)
     self.assertEqual(execute_args[4], ('select_count_for_words_sql 3', word_list))
     self.assertEqual(execute_args[5], ('insert_row_for_words_sql 3', word_list + [1]))
开发者ID:Macman1234,项目名称:pythontumblrbot,代码行数:12,代码来源:db_test.py

示例2: test_get_word_counts_works_correctly

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
 def test_get_word_counts_works_correctly(self):
     db = Db(self.conn, self.sql)
     db.setup(3)
     word_list = ['i', 'like']
     self.conn.stub_cursor.execute_results = [[['dogs',  1], ['cats',  2], ['frogs', 3]]]
     
     word_counts = db.get_word_count(word_list)
     
     self.assertEqual(word_counts, {'dogs' : 1, 'cats' : 2, 'frogs' : 3})
     execute_args = self.conn.stub_cursor.execute_args
     self.assertEqual(len(execute_args), 5)
     self.assertEqual(execute_args[4], ('select_words_and_counts_sql 3', word_list))
开发者ID:Macman1234,项目名称:pythontumblrbot,代码行数:14,代码来源:db_test.py

示例3: test_update_row_when_add_repeated_word_list

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
    def test_update_row_when_add_repeated_word_list(self):
        db = Db(self.conn, self.sql)
        db.setup(3)
        row_count = 10
        word_list = ['one', 'two', 'three']
        self.conn.stub_cursor.fetchone_results.append([row_count])

        db.add_word(word_list)
        
        execute_args = self.conn.stub_cursor.execute_args
        self.assertEqual(len(execute_args), 6)
        self.assertEqual(execute_args[4], ('select_count_for_words_sql 3', word_list))
        self.assertEqual(execute_args[5], ('update_count_for_words_sql 3', [row_count + 1] + word_list))
开发者ID:Macman1234,项目名称:pythontumblrbot,代码行数:15,代码来源:db_test.py

示例4: main

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
def main():
    
    #args = sys.argv

    #mode = choose_mode()

    response = new_or_load()
    
    depth = 1
    
    file_name = 'text/soldier_game.txt'
    #file_name = 'text/hitchhickers.txt'
    #file_name = 'text/soldier_game_short.txt'
    #file_name = 'text/soldier_game_short_segmented.txt'
    
    name  = 'soldierGame'
    #name  = 'hitchHikers'
    #name = 'soldierGameShort'
    #name = 'soldierGameShortSegmented'
    db_dir = 'db/'
    
    
    count = 1
        
    
    if response == 'n':
        usage = 'Usage: %s (parse <name> <depth> <path to txt file>|gen <name> <count>)' % ('parse', )

        db = Db(sqlite3.connect(db_dir + name + '.db'), Sql())
        #db = Db(sqlite3.connect(name + '.db'), Sql())
        db.setup(depth)
                
        txt = codecs.open(file_name, 'r', 'utf-8').read()
        Parser(name, db, SENTENCE_SEPARATOR, WORD_SEPARATOR).parse(txt)
    
    #elif mode == 'gen':
    #count = int(args[3])
    db = Db(sqlite3.connect(db_dir + name + '.db'), Sql())
    #db = Db(sqlite3.connect(name + '.db'), Sql())
    generator = Generator(name, db, Rnd())
    for i in range(0, count):
        print generator.generate(WORD_SEPARATOR)

    print''
    print''
开发者ID:vanstorm9,项目名称:LyricGenerator,代码行数:47,代码来源:markov.py

示例5: main

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
def main():
	args = sys.argv
	usage = 'Usage: %s (parse <name> <depth> <path to txt file>|gen <name> <count>)' % (args[0], )

	if (len(args) < 3):
		raise ValueError(usage)

	mode  = args[1]
	name  = args[2]
	
	if mode == 'parse':
		if (len(args) != 5):
			raise ValueError(usage)
		
		depth = int(args[3])
		file_name = args[4]
		
		db = Db(sqlite3.connect(name + '.db'), Sql())
		db.setup(depth)
		
		txt = codecs.open(file_name, 'r', 'utf-8').read()
		Parser(name, db, SENTENCE_SEPARATOR, WORD_SEPARATOR).parse(txt)
	
	elif mode == 'gen':
		count = int(args[3])
		db = Db(sqlite3.connect(name + '.db'), Sql())
		generator = Generator(name, db, Rnd())
		for i in range(0, count):
			output = generator.generate(WORD_SEPARATOR) + '.'
			# START code to lengthen tweets
			if len(output) < 100:
				output2 = output
				output = generator.generate(WORD_SEPARATOR) + '. ' + output
				if len(output) >140:
					output = output2
			# END code to lengthen tweets
			while len(output) > 140:
				output = generator.generate(WORD_SEPARATOR) + '.'
				print output
			print output
			tweet_output(output)
	
	else:
		raise ValueError(usage)
开发者ID:mence,项目名称:startupomatic,代码行数:46,代码来源:drakeomatic.py

示例6: ValueError

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
	usage = 'Usage: %s (parse <name> <depth> <path to txt file>|gen <name> <count>)' % (args[0], )

	if (len(args) < 3):
		raise ValueError(usage)

	mode  = args[1]
	name  = args[2]

	if mode == 'parse':
		if (len(args) != 5):
			raise ValueError(usage)

		depth = int(args[3])
		file_name = args[4]

		db = Db(sqlite3.connect(name + '.db'), Sql())
		db.setup(depth)

		txt = codecs.open(file_name, 'r', 'utf-8').read()
		Parser(name, db, SENTENCE_SEPARATOR, WORD_SEPARATOR).parse(txt)

	elif mode == 'gen':
		count = int(args[3])
		db = Db(sqlite3.connect(name + '.db'), Sql())
		generator = Generator(name, db, Rnd())
		for i in range(0, count):
			print generator.generate(WORD_SEPARATOR)

	else:
		raise ValueError(usage)
开发者ID:Macman1234,项目名称:pythontumblrbot,代码行数:32,代码来源:oldmarkov.py

示例7: Parse

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
def Parse(name, depth, file_name):
	db = Db(sqlite3.connect(name + '.db'), Sql())
	db.setup(depth)

	txt = codecs.open(file_name, 'r', 'utf-8').read()
	Parser(name, db, SENTENCE_SEPARATOR, WORD_SEPARATOR).parse(txt)
开发者ID:Macman1234,项目名称:pythontumblrbot,代码行数:8,代码来源:markov.py

示例8: test_db_commit_performed_correctly

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
 def test_db_commit_performed_correctly(self):
     db = Db(self.conn, self.sql)
     db.setup(3)
     self.assertEqual(self.conn.commit_count, 0)
     db.commit()
     self.assertEqual(self.conn.commit_count, 1)
开发者ID:Macman1234,项目名称:pythontumblrbot,代码行数:8,代码来源:db_test.py

示例9: test_error_when_add_word_count_wrong

# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import setup [as 别名]
 def test_error_when_add_word_count_wrong(self):
     db = Db(self.conn, self.sql)
     db.setup(3)
     self.assertRaises(ValueError, db.add_word, ['one','two'])
开发者ID:Macman1234,项目名称:pythontumblrbot,代码行数:6,代码来源:db_test.py


注:本文中的db.Db.setup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。