<s> __author__ = """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from os import getcwd <EOL> from os import sys <EOL> sys . path . append ( getcwd ( ) ) <EOL> from MOAL . helpers . display import Section <EOL> from MOAL . helpers . display import prnt <EOL> from MOAL . helpers . trials import run_trials <EOL> from MOAL . helpers . trials import test_speed <EOL> from datetime import datetime as dt <EOL> from faker import Factory <EOL> from pymongo import MongoClient <EOL> DEBUG = True if __name__ == '<STR_LIT:__main__>' else False <EOL> _count = <NUM_LIT:0> <EOL> _testdata = [ ] <EOL> faker = Factory . create ( ) <EOL> client = MongoClient ( ) <EOL> db = client [ '<STR_LIT>' ] <EOL> collection = db [ '<STR_LIT>' ] <EOL> def make_person ( ) : <EOL> return { <EOL> '<STR_LIT:name>' : faker . name ( ) , <EOL> '<STR_LIT:email>' : faker . email ( ) , <EOL> '<STR_LIT:address>' : faker . address ( ) , <EOL> '<STR_LIT:url>' : faker . url ( ) , <EOL> '<STR_LIT>' : dt . now ( ) <EOL> } <EOL> @ test_speed <EOL> def insert_all ( max_records ) : <EOL> global _count <EOL> global _testdata <EOL> for n in range ( max_records ) : <EOL> _count += <NUM_LIT:1> <EOL> data = make_person ( ) <EOL> _testdata . append ( data [ '<STR_LIT:name>' ] ) <EOL> collection . insert ( data ) <EOL> if DEBUG : <EOL> with Section ( '<STR_LIT>' ) : <EOL> collection . remove ( ) <EOL> print ( collection . count ( ) ) <EOL> run_trials ( insert_all , trials = <NUM_LIT:10> ) <EOL> res = collection . find ( { } ) <EOL> mongo_res = [ ] <EOL> for k , item in enumerate ( res ) : <EOL> mongo_res . append ( item [ '<STR_LIT:name>' ] ) <EOL> prnt ( '<STR_LIT>' , mongo_res ) <EOL> assert sorted ( mongo_res ) == sorted ( _testdata ) <EOL> assert _count == collection . count ( ) </s>
