def should_not_be_equal(self, expected, actual): are_equal = expected == actual if not are_equal: self.tests_passed = self.tests_passed + 1 else: ppp('actual value:', actual, 'shouldn\'t equal expected value:', expected) self.tests_total = self.tests_total + 1
def should_not_be_equal(self, expected, actual): are_equal = expected == actual if not are_equal: self.tests_passed = self.tests_passed + 1 else: ppp('actual value: {0} shouldn\'t equal expected value: {1}'.format( expected, actual )) self.tests_total = self.tests_total + 1
# 'empty_object': object(), # not json serializable # 'set': set(), # not json serializable # 'tuple': tuple() # serializes to list (array) } cache_ttl = 1 # test single items for cache_key, cache_value in cache_items.items(): # test set set_response = redis_driver.set( key=cache_key, value=cache_value, ttl=cache_ttl ) ppp('set_response for {0}:'.format(cache_key), set_response) t.should_be_equal(expected=True, actual=set_response) # test get before expiration get_response = redis_driver.get(key=cache_key) ppp('get_response for {0}:'.format(cache_key), get_response) t.should_be_equal(expected=cache_value, actual=get_response) # test get after expiration time.sleep(2) get_response = redis_driver.get(key=cache_key) ppp('get_response for {0}:'.format(cache_key), get_response) t.should_be_equal(expected=None, actual=get_response) # test delete redis_driver.set(cache_key, cache_value)
import sys sys.path.append('..') import config.config as config from data_store.database_driver.mysql_driver import MySqlDriver from data_store.database_config.mysql.master_mysql_db import MasterMySqlDB from utils.print import ppp mysql_driver = MySqlDriver(db_config=MasterMySqlDB.get_instance()) create_table_query = """ CREATE TABLE IF NOT EXISTS wall_message ( uuid VARCHAR(32) PRIMARY KEY, created_ts INT(11) NOT NULL, updated_ts INT(11) NOT NULL, message VARCHAR(1000), attribution VARCHAR(255) ) """ query_result = mysql_driver.query_bind(query_string=create_table_query) ppp('result of create table query:', query_result)
import sys sys.path.append('..') from utils.print import ppp my_int = 123 ppp(my_int, my_int) my_list = ['hi', 'there'] ppp(my_list, my_list) ppp(my_list, my_list, as_json=1) my_tuple = (1.23, 'hello', False) ppp(my_tuple, my_tuple) ppp(my_tuple, my_tuple, as_json=1) my_dict = { 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
import sys sys.path.append('..') from data_store.database_config.mysql.master_mysql_db import MasterMySqlDB from testie import Testie from utils.print import ppp t = Testie() master_db_instance_1 = MasterMySqlDB.get_instance() master_db_instance_2 = MasterMySqlDB.get_instance() ppp('master_db_instance_1:', master_db_instance_1) ppp('master_db_instance_2:', master_db_instance_2) t.should_be_equal(actual=True, expected=master_db_instance_1 == master_db_instance_2) db = MasterMySqlDB.get_instance() TABLE_NAME = 'test_table' # test table deletion drop_table_query = """ DROP TABLE IF EXISTS {0} """.format(TABLE_NAME) db.cur.execute(drop_table_query) res = db.cur.fetchall() ppp('drop table query response:', res) t.should_be_equal(actual=type(res), expected=tuple) t.should_be_equal(actual=len(res), expected=0)
""" t = Testie() mysql_driver = MySqlDriver(db_config=MasterMySqlDB.get_instance()) redis_driver = RedisDriver(cache_config=MasterRedisCache.get_instance()) TABLE_NAME = 'test_user' ######## DELETE TEST TABLE ######## drop_table_query = """ DROP TABLE IF EXISTS {0} """.format(TABLE_NAME) query_result = mysql_driver.query_bind(query_string=drop_table_query) ppp('result of drop table query:', query_result) ######## CREATE TEST TABLE ######## create_table_query = """ CREATE TABLE IF NOT EXISTS {0} ( uuid VARCHAR(32) PRIMARY KEY, created_ts INT(11) NOT NULL, updated_ts INT(11) NOT NULL, name VARCHAR(255), age INT(4), admin TINYINT(1) ) """.format(TABLE_NAME) query_result = mysql_driver.query_bind(query_string=create_table_query) ppp('result of create table query:', query_result)
import sys sys.path.append('..') from data_object.word_data_object import WordDataObject from service.word import Word from service.language import Language from utils.print import ppp # random word list options language = Language(Language.ENGLISH) qwerty_difficulty_rank = {'min': 0, 'max': 10000} frequency_rank = {'min': 0, 'max': 10000} length = {'min': 0, 'max': 100} substring = 'ba' limit = 10 word_list = Word.get_random_list(language=language, qwerty_difficulty_rank=qwerty_difficulty_rank, frequency_rank=frequency_rank, length=length, substring=substring, limit=limit) ppp(word_list) for wordDO in word_list: ppp(wordDO.to_dict()) ppp("length: {0}".format(len(word_list)))
from data_object.word_data_object import WordDataObject from service.keyboard import Keyboard from service.language import Language from utils.print import ppp keyboard = Keyboard(Keyboard.QWERTY, Language.ENGLISH) with open('../../sources/word_sources/number27.org/words_90K.txt', 'r') as file: for line_index, line in enumerate(file): parts = [x.strip('() ') for x in line.split(',')] word_props = { 'text': parts[0], 'length': len(parts[0]), 'frequency': float(parts[1]), 'frequency_rank': line_index + 1, 'qwerty_difficulty': keyboard.get_keyboard_difficulty_for_word( parts[0], round_to_int=True ) } wordDO = WordDataObject.create( prop_dict=word_props, language=WordDataObject.ENGLISH ) res = wordDO.save() ppp(res.to_dict())
# created_ts INT(11) NOT NULL, # updated_ts INT(11) NOT NULL, # # table specific columns here: # typing_test_id INT(6) UNSIGNED NOT NULL, # user_id INT(6) UNSIGNED NOT NULL, # status TINYINT(1) UNSIGNED NOT NULL, # test_time INT(4) UNSIGNED, # wpm INT(3) UNSIGNED # ) # """ # create user_typing_test_content table # create_table_query = """ # CREATE TABLE IF NOT EXISTS user_typing_test_content ( # id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, # created_ts INT(11) NOT NULL, # updated_ts INT(11) NOT NULL, # # table specific columns here: # user_typing_test_id INT(6) UNSIGNED NOT NULL, # word_id INT(6) UNSIGNED NOT NULL, # position INT(4) UNSIGNED NOT NULL, # attempted TINYINT(1) UNSIGNED, # completed_correctly TINYINT(1) UNSIGNED, # completion_time INT(4) # ) # """ query_result = mysql_driver.query(query_string=create_table_query) ppp(['result of create table query:', query_result])
import sys sys.path.append('..') from service.language import Language from utils.print import ppp language = Language(Language.ENGLISH) ppp('language type: {}'.format(language.get_type())) ppp('language letter frequency for "J": {}'.format( language.get_letter_frequency('J')))
import sys sys.path.append('../..') from data_store.database_driver.mysql_driver import MySqlDriver from data_object.word_data_object import WordDataObject from service.language import Language from utils.print import ppp # get all words from table ordered by QWERTY difficulty # save with additional QWERTY difficulty rank value db = MySqlDriver(database_name='zentype') sql = 'SELECT * FROM english_word ORDER BY qwerty_difficulty' word_datas = db.query(sql) language = Language(Language.ENGLISH) curr_difficulty_rank = 1 for word_data in word_datas: word_data['qwerty_difficulty_rank'] = curr_difficulty_rank word_DO = WordDataObject.create(prop_dict=word_data, language=language) save_res = word_DO.save() ppp(save_res) curr_difficulty_rank = curr_difficulty_rank + 1 ppp('All done!')
def print_report(self): ppp('test results: {0}/{1}'.format( self.tests_passed, self.tests_total ))
'maiden_name': None }) expected_where_clause = "WHERE `id` = %s AND `name` LIKE %s AND `age` > %s AND \ `age` <= %s AND `age` <> %s AND `height` IN (%s,%s,%s,%s) AND `race` IS NOT %s \ AND `maiden_name` IS %s" t.should_be_equal(expected=expected_where_clause, actual=where_clause) ######## TEST 'ORDER BY' CLAUSE BUILDER ######## order_by_field = 'uuid' order_by_direction = 'descending' order_by_clause = MySqlDriver.construct_order_by_clause( field=order_by_field, direction=order_by_direction) ppp('order by uuid descending clause:', order_by_clause) t.should_be_equal(expected='ORDER BY {} {}'.format(order_by_field, 'DESC'), actual=order_by_clause) order_by_field = 'name' order_by_direction = None order_by_clause = MySqlDriver.construct_order_by_clause( field=order_by_field, direction=order_by_direction) ppp('order by name default order clause:', order_by_clause) t.should_be_equal(expected='ORDER BY {}'.format(order_by_field), actual=order_by_clause) order_by_field = 'name' order_by_direction = 'does not exist' order_by_clause = MySqlDriver.construct_order_by_clause( field=order_by_field, direction=order_by_direction)
from service.language import Language from utils.print import ppp language = Language(Language.ENGLISH) word_qwerty_difficulty_rank = { 'min': 0, 'max': 10000 } word_frequency_rank = { 'min': 0, 'max': 10000 } word_length = { 'min': 0, 'max': 100 } word_count = 10 typing_test = TypingTest.build_wpm_typing_test( language=language, word_qwerty_difficulty_rank=word_qwerty_difficulty_rank, word_frequency_rank=word_frequency_rank, word_length=word_length, word_count=word_count, ) ppp(typing_test)
import sys sys.path.append('..') from data_store.mysql_driver import MySqlDriver from utils.print import ppp # create user table create_user_table_query = """ CREATE TABLE IF NOT EXISTS user ( `uuid4` VARCHAR(32) PRIMARY KEY, `name` VARCHAR(255) NOT NULL UNIQUE ) """ query_result = MySqlDriver.query_bind(query_string=create_user_table_query) ppp('result of create "user" table query:', query_result) # create task table create_task_table_query = """ CREATE TABLE IF NOT EXISTS task ( `uuid4` VARCHAR(32) PRIMARY KEY, `title` VARCHAR(1000) NOT NULL ) """ query_result = MySqlDriver.query_bind(query_string=create_task_table_query) ppp('result of create "task" table query:', query_result) # create vote table create_vote_table_query = """ CREATE TABLE IF NOT EXISTS vote ( `uuid4` VARCHAR(32) PRIMARY KEY,
import sys sys.path.append('..') from operator import itemgetter from service.keyboard import Keyboard from service.language import Language from utils.print import ppp keyboard = Keyboard(Keyboard.QWERTY, Language.ENGLISH) for key in keyboard.keyboard_model: ppp(key.to_dict()) lingo = Language(Language.ENGLISH) ppp(lingo.letter_frequencies) word_text = 'word' for ch in word_text: key = keyboard.get_key_from_character(ch) ppp(key.to_dict()) sentence = """ In 1758, the taxonomist Linnaeus published in his Systema Naturae the classification of species. Canis is a Latin word meaning dog,[33] and under this genus he listed the dog-like carnivores including domestic dogs, wolves, and jackals. He classified the domestic dog as Canis familiaris and on the next page as a separate species he classified the wolf as Canis lupus.[2] In 1926, the International Commission on Zoological Nomenclature (ICZN) in Opinion 91 included Genus Canis on its Official Lists and Indexes of Names in Zoology.[3] In 1955, the ICZN's Direction 22 added Canis familiaris as the type species for genus Canis to the official list.[34] In
from utils.print import ppp """ Test WallMessages service. Requires creation of 'wall_message' MySQL table via create-wall-messages-table.py script. """ t = Testie() message_body = 'hello, world!' message_attribution = 'harry' added_wm = WallMessages.add_message(message_body=message_body, message_attribution=message_attribution) ppp(['added wall message:', added_wm.to_dict()]) t.should_be_equal(expected=message_body, actual=added_wm.get_prop('message')) t.should_be_equal(expected=message_attribution, actual=added_wm.get_prop('attribution')) found_wm = WallMessages.find_one(message_uuid=added_wm.get_prop('uuid')) ppp(['found wall message:', found_wm.to_dict()]) t.should_be_equal(expected=added_wm.to_dict(), actual=found_wm.to_dict()) updated_message_body = 'i am the new message' updated_message_attribution = 'newman' updated_wm = WallMessages.update_message( message_uuid=added_wm.get_prop('uuid'),