Best Python code snippet using localstack_python
test_stores.py
Source:test_stores.py
...5 CrossRegionAttribute,6 LocalAttribute,7)8@fixture9def sample_stores() -> AccountRegionBundle:10 class SampleStore(BaseStore):11 CROSS_REGION_ATTR = CrossRegionAttribute(default=list)12 region_specific_attr = LocalAttribute(default=list)13 return AccountRegionBundle("zzz", SampleStore, validate=False)14class TestStores:15 def test_store_reset(self, sample_stores):16 """Ensure reset functionality of Stores and encapsulation works."""17 account1 = "696969696969"18 account2 = "424242424242"19 eu_region = "eu-central-1"20 ap_region = "ap-south-1"21 store1 = sample_stores[account1][eu_region]22 store2 = sample_stores[account1][ap_region]23 store3 = sample_stores[account2][ap_region]...
analysis.py
Source:analysis.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3from pprint import pprint as pp4import json5from zipfile import ZipFile6import pymongo7outfile = 'openstreetmapdata.json'8# insert into MongoDB database9connection = pymongo.MongoClient('localhost', 27017)10if 'openstreetmap' in connection.list_database_names():11 db = connection['openstreetmap']12 db.main.drop() 13 print('Deleted existing database')14print 'Making new database openstreetmap'15db = connection['openstreetmap']16with open(outfile) as f:17 data = [json.loads(line) for line in f]18 db.main.insert_many(data)19 20# explore the db with PyMongo21#find size stats of database22# database stats23stats = 'dbstats', db.command('dbstats') 24pp(stats)25#size of file in KB26print db.command('dbstats')['storageSize'] / 1024, 'KB file'27# how many nodes, ways, and relations28print29print db.main.find().count(), 'total documents\n'30print db.main.count_documents({'type':'node'}), 'nodes'31print db.main.count_documents({'type':'way'}), 'ways'32print db.main.count_documents({'type':'relation'}), 'relations\n'33#how many unique users34print len(db.main.distinct('created.user')), 'unique users\n'35#Which 5 users contributed the most to the data?36result = db.main.aggregate([{'$group' : { '_id' : '$created.user',37 'count' : {'$sum': 1}}},38 {'$sort' : {'count' : -1 }},39 {'$limit' : 5}])40print 'Top 5 contributers'41for doc in result:42 print doc43 44# number of busstops45print db.main.count_documents({'highway':'bus_stop'}), 'bus stops'46# which node is referenced the most?47 48result = db.main.aggregate([ {'$match' : {'type' : {'$in': ['way', 'relation']}}},49 {'$unwind': '$node_refs'},50 {'$group': {'_id' : '$node_refs',51 'count' :{'$sum': 1}}},52 {'$sort' : { 'count' : -1 }},53 {'$limit' : 1 }])54print 'Here is the most referenced node:\n'55for doc in result: 56 id = doc['_id']57 for i in db.main.find({'id' : id}):58 pp(i)59 print 'Referenced in', doc['count'], 'records'60 coords = i['pos']61# 5 closest retaurants to that node62#build index on id, geo2d index on pos field63db.main.create_index([('pos', pymongo.GEO2D)])64closest_restaurants = db.main.find({'pos' : {'$near': coords}, 'amenity' : 'restaurant'}).limit(5)65print '\nFive nearest restaurants \n'66for i in closest_restaurants: 67 print i['name']68 if 'address' in i:69 print i['address']['housenumber'], i['address']['street']70 else:71 print 'No address given'72 if 'cuisine' in i:73 print 'Cuisine', i['cuisine']74 print '----------------'75# give us 3 restaurants that are missing address data76sample_restaurants = db.main.find({'type' : 'node', 'amenity':'restaurant', 'address': {'$exists' : False}}).limit(3)77print 'Restaurants'78for doc in sample_restaurants:79 pp(doc)80 print81# give us 3 shops that are missing address data82sample_stores = db.main.find({'shop' : {'$exists' : True}, 'address' : {'$exists' : False}}).limit(3)83print 'Shops'84for doc in sample_stores:85 pp(doc)86 print...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!