How to use build_description method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

build_query.py

Source:build_query.py Github

copy

Full Screen

1#this class will contain methods which we2#use later to3# map a version # -> rpm url4from datetime import datetime5import time6import urllib27import re8import BeautifulSoup9class MembaseBuild(object):10 def __init__(self):11 self.url = ''12 self.name = ''13 self.time = ''14 self.size = ''15 self.product = ''16 self.product_version = ''17 self.build_number = 018 self.os = ''19 self.deliverable_type = ''20 self.architecture_type = ''21 self.toy = ''22 self.change = None # a MembaseChange23 def __repr__(self):24 return self.__str__()25 #let's also have a json object for all these classes26 def __str__(self):27 url = 'url : {0}'.format(self.url)28 name = 'name : {0}'.format(self.name)29 product = 'product : {0}'.format(self.product)30 product_version = 'product_version : {0}'.format(self.product_version)31 os = 'os : {0}'.format(self.os)32 deliverable_type = 'deliverable_type : {0}'.format(self.deliverable_type)33 architecture_type = 'architecture_type : {0}'.format(self.architecture_type)34 if self.toy:35 toy = 'toy : {0}'.format(self.toy)36 else:37 toy = ''38 return '{0} {1} {2} {3} {4} {5} {6} {7}'.format(url, name, product, product_version, os, deliverable_type,39 architecture_type, toy)40class MembaseChange(object):41 def __init__(self):42 self.url = ''43 self.name = ''44 self.time = ''45 self.build_number = ''46class BuildQuery(object):47 def __init__(self):48 pass49 # let's look at buildlatets or latest/sustaining or any other50 # location51 def parse_builds(self):52 #parse build page and create build object53 pass54 def find_build(self,builds,product,type,arch,version,toy=''):55 for build in builds:56 if build.product_version.find(version) != -1 and product == build.product\57 and build.architecture_type == arch and type == build.deliverable_type\58 and build.toy == toy:59 return build60 return None61 def find_membase_build(self, builds, product, deliverable_type, os_architecture, build_version, is_amazon=False):62 if is_amazon:63 build = BuildQuery().find_build(builds, product, deliverable_type,64 os_architecture, build_version)65 if build:66 build.url = build.url.replace("http://builds.hq.northscale.net",\67 "http://packages.northscale.com.s3.amazonaws.com")68 build.url = build.url.replace("enterprise", "community")69 build.name = build.name.replace("enterprise", "community")70 return build71 for build in builds:72 if build.product_version.find(build_version) != -1 and product == build.product\73 and build.architecture_type == os_architecture and deliverable_type == build.deliverable_type:74 return build75 return None76 def find_membase_build_with_version(self, builds, build_version):77 for build in builds:78 if build.product_version == build_version or build.product_version.find(build_version) != -1:79 #or if it starts with that version ?80 return build81 return None82 def find_membase_release_build(self, product, deliverable_type, os_architecture, build_version, is_amazon=False):83 build_details = build_version84 if build_version.startswith("1.7.2"):85 build_details = "1.7.2r-20-g6604356"86 elif build_version.startswith("1.8.0"):87 build_details = "1.8.0r-55-g80f24f2"88 product = "couchbase-server-enterprise"89 build = MembaseBuild()90 build.deliverable_type = deliverable_type91 build.time = '0'92 build.size = '0'93 build.product_version = build_version94 build.architecture_type = os_architecture95 build.product = product96 build.name = '{1}_{2}_{0}.{3}'.format(build_version, product, os_architecture, deliverable_type)97 build.build_number = 098 if deliverable_type == "exe":99 build.url = 'http://builds.hq.northscale.net/releases/{0}/{1}_{2}_{4}.setup.{3}'.format(build_version, product, os_architecture, deliverable_type, build_details)100 else:101 build.url = 'http://builds.hq.northscale.net/releases/{0}/{1}_{2}_{4}.{3}'.format(build_version, product, os_architecture, deliverable_type, build_details)102 # This points to the Internal s3 account to look for release builds103 if is_amazon:104 build.url = 'https://s3.amazonaws.com/packages.couchbase/releases/{0}/{1}_{2}_{0}.{3}'.format(build_version, product, os_architecture, deliverable_type)105 build.url = build.url.replace("enterprise", "community")106 build.name = build.name.replace("enterprise", "community")107 return build108 def sort_builds_by_version(self, builds):109 membase_builds = list()110 for build in builds:111 if build.product == 'membase-server-enterprise':112 membase_builds.append(build)113 return sorted(membase_builds,114 key=lambda membase_build: membase_build.build_number, reverse=True)115 def sort_builds_by_time(self, builds):116 membase_builds = list()117 for build in builds:118 if build.product == 'membase-server-enterprise':119 membase_builds.append(build)120 return sorted(membase_builds,121 key=lambda membase_build: membase_build.time, reverse=True)122 def get_latest_builds(self):123 return self._get_and_parse_builds('http://builds.hq.northscale.net/latestbuilds')124 def get_sustaining_latest_builds(self):125 return self._get_and_parse_builds('http://builds.hq.northscale.net/latestbuilds/sustaining')126 def get_all_builds(self):127 try:128 latestbuilds, latestchanges =\129 self._get_and_parse_builds('http://builds.hq.northscale.net/latestbuilds')130 except:131 latestbuilds, latestchanges =\132 self._get_and_parse_builds('http://packages.northscale.com.s3.amazonaws.com/latestbuilds')133 try:134 sustaining_builds, sustaining_changes =\135 self._get_and_parse_builds('http://builds.hq.northscale.net/latestbuilds/sustaining')136 except:137 sustaining_builds, sustaining_changes =\138 self._get_and_parse_builds('http://packages.northscale.com.s3.amazonaws.com/latestbuilds/sustaining')139 latestbuilds.extend(sustaining_builds)140 latestchanges.extend(sustaining_changes)141 return latestbuilds, latestchanges142 #baseurl = 'http://builds.hq.northscale.net/latestbuilds/'143 def _get_and_parse_builds(self, build_page):144 builds = []145 changes = []146 page = None147 soup = None148 #try this five times149 for i in range(0, 5):150 try:151 page = urllib2.urlopen(build_page + '/index.html')152 soup = BeautifulSoup.BeautifulSoup(page)153 break154 except:155 time.sleep(1)156 if not page:157 raise Exception('unable to connect to builds.hq')158 query = BuildQuery()159 for incident in soup('li'):160 contents = incident.contents161 build_id = ''162 build_description = ''163 for content in contents:164 if BeautifulSoup.isString(content):165 build_description = content.string166 elif content.name == 'a':167 build_id = content.string.string168 if build_id.lower().startswith('changes'):169 change = query.create_change_info(build_id, build_description)170 change.url = '%s/%s' % (build_page, build_id)171 changes.append(change)172 else:173 build = query.create_build_info(build_id, build_description)174 build.url = '%s/%s' % (build_page, build_id)175 builds.append(build)176 #now let's reconcile the builds and changes?177 for build in builds:178 for change in changes:179 if change.build_number == build.product_version:180 build.change = change181 # print 'change : ', change.url,change.build_number182 break183 #let's filter those builds with version that starts with 'v'184 filtered_builds = []185 for build in builds:186 # if not '{0}'.format(build.product_version).startswith('v'):187 filtered_builds.append(build)188 return filtered_builds, changes189 def create_build_info(self, build_id, build_decription):190 build = MembaseBuild()191 build.deliverable_type = self._product_deliverable_type(build_id)192 build.time = self._product_time(build_decription)193 build.size = self._product_size(build_decription)194 build.product_version = self._product_version(build_id)195 build.architecture_type = self._product_arch_type(build_id)196 build.product = self._product_name(build_id)197 build.name = build_id198 build.build_number = self._build_number(build)199 build.toy = self._product_toy(build_id)200 return build201 def create_change_info(self, build_id, build_decription):202 change = MembaseChange()203 change.name = build_id.strip()204 change.build_number = self._change_build_number(build_id)205 change.time = self._change_time(build_decription)206 return change207 def _product_name(self, build_id):208 list = build_id.split('_')209 return list[0]210 #the first one is the product211 def _product_arch_type(self, build_id):212 list = build_id.split('_')213 if '64' in build_id.split('_'):214 return 'x86_64'215 elif 'x86' in build_id.split('_'):216 return 'x86'217 return ''218 def _product_toy(self, build_id):219 r = re.search("[^_]+_toy-([^-]*)-x86",build_id)220 if r:221 return r.group(1)222 return ''223 def _change_time(self, build_description):224 list = build_description.split('/')225 timestamp = list[1].strip()226 timestamp = timestamp[:timestamp.index(')')]227 return datetime.strptime(timestamp, '%a %b %d %H:%M:%S %Y')228 def _change_build_number(self, build_id):229 list = build_id.split('_')230 #get list[1] . get rid of .txt231 build_number = list[1].strip()232 if re.search('.txt', build_number):233 build_number = build_number[:build_number.index('.txt')]234 return build_number235 def _build_number(self, build):236 #get the first - and then the first - after that237 first_dash = build.product_version.find('-')238 if first_dash != -1:239 second_dash = build.product_version.find('-', first_dash + 1)240 if second_dash != -1:241 try:242 return int(build.product_version[first_dash + 1:second_dash])243 except Exception:244 return -1245 return -1246 def _product_version(self, build_id):247 list = build_id.split('_')248 version_item = ''249 for item in list:250 if item.endswith('.setup.exe') or item.endswith('rpm') or\251 item.endswith('deb') or item.endswith('tar.gz'):252 version_item = item253 break254 if version_item != '':255 if version_item.endswith('.setup.exe'):256 return version_item[:version_item.index('.setup.exe')]257 elif version_item.endswith('.tar.gz'):258 return version_item[:version_item.index('.tar.gz')]259 elif version_item.endswith('.deb'):260 return version_item[:version_item.index('.deb')]261 elif version_item.endswith('.rpm'):262 return version_item[:version_item.index('.rpm')]263 return ''264 def _product_deliverable_type(self, build_id=''):265 list = build_id.split('_')266 version_item = ''267 for item in list:268 if item.endswith('.setup.exe') or item.endswith('rpm') or\269 item.endswith('deb') or item.endswith('tar.gz'):270 version_item = item271 break272 if version_item != '':273 if version_item.endswith('.setup.exe'):274 return 'exe'275 elif version_item.endswith('.tar.gz'):276 return 'tar.gz'277 elif version_item.endswith('.deb'):278 return 'deb'279 elif version_item.endswith('.rpm'):280 return 'rpm'281 return ''282 def _product_time(self, build_description):283 list = build_description.split('/')284 timestamp = list[1].strip()285 timestamp = timestamp[:timestamp.index(')')]286 return datetime.strptime(timestamp, '%a %b %d %H:%M:%S %Y')287 def _product_size(self, build_description):288 list = build_description.split('/')289 filesize = list[0]290 filesize = filesize[filesize.index('(') + 1:]291 return filesize.strip()292#q = BuildQuery()293#builds, changes = q.get_latest_builds()294#for build in builds:295# print build.product,' ',build.time ,' ',build.deliverable_type,' ',build.product_version ,'',build.size,'',build.architecture_type296# if build.change:297# change = build.change298# print change.name,change.build_number,change.time,change.url299#for change in changes:300# print change.name,change.build_number,change.time301#builds = q.get_membase_latest_builds()302#for build in builds:...

Full Screen

Full Screen

test_format.py

Source:test_format.py Github

copy

Full Screen

...36 def test_simple_tree(self):37 logging.getLogger('a')38 logging.getLogger('a.b').setLevel(logging.DEBUG)39 logging.getLogger('x.c')40 self.assertEqual(build_description(), '''\41<--""42 Level WARNING43 |44 o<--"a"45 | Level NOTSET so inherits level WARNING46 | |47 | o<--"a.b"48 | Level DEBUG49 |50 o<--[x]51 |52 o<--"x.c"53 Level NOTSET so inherits level WARNING54''')55 def test_fancy_tree(self):56 logging.getLogger('').setLevel(logging.DEBUG)57 log = logging.getLogger('db')58 log.setLevel(logging.INFO)59 log.propagate = False60 log.disabled = 161 log.addFilter(MyFilter())62 handler = logging.StreamHandler()63 handler.setFormatter(logging.Formatter())64 log.addHandler(handler)65 handler.addFilter(logging.Filter('db.errors'))66 logging.getLogger('db.errors')67 logging.getLogger('db.stats')68 log = logging.getLogger('www.status')69 log.setLevel(logging.DEBUG)70 log.addHandler(logging.FileHandler('/foo/log.txt'))71 log.addHandler(MyHandler())72 self.assertEqual(build_description(), '''\73<--""74 Level DEBUG75 |76 o "db"77 | Level INFO78 | Propagate OFF79 | Disabled80 | Filter <MyFilter>81 | Handler Stream %r82 | Filter name='db.errors'83 | Formatter fmt='%%(message)s' datefmt=None84 | |85 | o<--"db.errors"86 | | Level NOTSET so inherits level INFO87 | |88 | o<--"db.stats"89 | Level NOTSET so inherits level INFO90 |91 o<--[www]92 |93 o<--"www.status"94 Level DEBUG95 Handler File '/foo/log.txt'96 Handler <MyHandler>97''' % (sys.stderr,))98 def test_most_handlers(self):99 ah = logging.getLogger('').addHandler100 ah(logging.handlers.RotatingFileHandler(101 '/bar/one.txt', maxBytes=10000, backupCount=3))102 ah(logging.handlers.SocketHandler('server.example.com', 514))103 ah(logging.handlers.DatagramHandler('server.example.com', 1958))104 ah(logging.handlers.SysLogHandler())105 ah(logging.handlers.SMTPHandler(106 'mail.example.com', 'Server', 'Sysadmin', 'Logs!'))107 # ah(logging.handlers.NTEventLogHandler())108 ah(logging.handlers.HTTPHandler('api.example.com', '/logs', 'POST'))109 ah(logging.handlers.BufferingHandler(20000))110 sh = logging.StreamHandler()111 ah(logging.handlers.MemoryHandler(30000, target=sh))112 self.assertEqual(build_description(), '''\113<--""114 Level WARNING115 Handler RotatingFile '/bar/one.txt' maxBytes=10000 backupCount=3116 Handler Socket server.example.com 514117 Handler Datagram server.example.com 1958118 Handler SysLog ('localhost', 514) facility=1119 Handler SMTP via mail.example.com to ['Sysadmin']120 Handler HTTP POST to http://api.example.com//logs121 Handler Buffering capacity=20000122 Handler Memory capacity=30000123 Flushes output to:124 Handler Stream %r125''' % (sh.stream,))126 logging.getLogger('').handlers[3].socket.close() # or Python 3 warning127 def test_2_dot_5_handlers(self):128 if sys.version_info < (2, 5):129 return130 ah = logging.getLogger('').addHandler131 ah(logging.handlers.TimedRotatingFileHandler('/bar/two.txt'))132 expected = '''\133<--""134 Level WARNING135 Handler TimedRotatingFile '/bar/two.txt' when='H' interval=3600 backupCount=0136'''137 self.assertEqual(build_description(), expected)138 def test_2_dot_6_handlers(self):139 if sys.version_info < (2, 6):140 return141 ah = logging.getLogger('').addHandler142 ah(logging.handlers.WatchedFileHandler('/bar/three.txt'))143 self.assertEqual(build_description(), '''\144<--""145 Level WARNING146 Handler WatchedFile '/bar/three.txt'147''')148 def test_nested_handlers(self):149 h1 = logging.StreamHandler()150 h2 = logging.handlers.MemoryHandler(30000, target=h1)151 h2.addFilter(logging.Filter('worse'))152 h2.setLevel(logging.ERROR)153 h3 = logging.handlers.MemoryHandler(30000, target=h2)154 h3.addFilter(logging.Filter('bad'))155 logging.getLogger('').addHandler(h3)156 self.assertEqual(build_description(), '''\157<--""158 Level WARNING159 Handler Memory capacity=30000160 Filter name='bad'161 Flushes output to:162 Handler Memory capacity=30000163 Level ERROR164 Filter name='worse'165 Flushes output to:166 Handler Stream %r167''' % (h1.stream,))168 def test_formatter_with_no_fmt_attributes(self):169 f = logging.Formatter()170 del f._fmt171 del f.datefmt172 h = logging.StreamHandler()173 h.setFormatter(f)174 logging.getLogger('').addHandler(h)175 self.assertEqual(build_description(), '''\176<--""177 Level WARNING178 Handler Stream %r179 Formatter fmt=None datefmt=None180''' % (h.stream,))181 def test_formatter_that_is_not_a_Formatter_instance(self):182 h = logging.StreamHandler()183 h.setFormatter("Ceci n'est pas une formatter")184 logging.getLogger('').addHandler(h)185 self.assertEqual(build_description(), '''\186<--""187 Level WARNING188 Handler Stream %r189 Formatter "Ceci n'est pas une formatter"190''' % (h.stream,))191 def test_handler_with_wrong_parent_attribute(self):192 logging.getLogger('celery')193 logging.getLogger('app.model')194 logging.getLogger('app.task').parent = logging.getLogger('celery.task')195 logging.getLogger('app.view')196 self.assertEqual(build_description(), '''\197<--""198 Level WARNING199 |200 o<--[app]201 | |202 | o<--"app.model"203 | | Level NOTSET so inherits level WARNING204 | |205 | o !-"app.task"206 | | Broken .parent redirects messages to 'celery.task' instead207 | | Level NOTSET so inherits level WARNING208 | |209 | o<--"app.view"210 | Level NOTSET so inherits level WARNING211 |212 o<--"celery"213 Level NOTSET so inherits level WARNING214 |215 o<--"celery.task"216 Level NOTSET so inherits level WARNING217''')218 def test_handler_with_parent_attribute_that_is_none(self):219 logging.getLogger('app').parent = None220 self.assertEqual(build_description(), '''\221<--""222 Level WARNING223 |224 o !-"app"225 Broken .parent is None, so messages stop here226 Level NOTSET so inherits level NOTSET227''')228class MyFilter(object):229 def __repr__(self):230 return '<MyFilter>'231class MyHandler(object):232 def __repr__(self):233 return '<MyHandler>'234if __name__ == '__main__': # for Python <= 2.4...

Full Screen

Full Screen

client.py

Source:client.py Github

copy

Full Screen

1from pprint import pprint2import yaml3import sys4from pybitbucket.auth import BasicAuthenticator5from pybitbucket.bitbucket import Client6from pybitbucket.build import BuildStatus, BuildStatusStates7class BuildJenkinsData:8 def __init__(self, jenkins_job_name, 9 jenkins_build_url = None,10 jenkins_build_name = None,11 jenkins_build_description = None):12 self.job_name = jenkins_job_name13 self.build_url = jenkins_build_url 14 15 if jenkins_build_name == None:16 self.build_name = jenkins_job_name17 else:18 self.build_name = jenkins_build_name19 if jenkins_build_description == None:20 self.build_description = jenkins_job_name21 else:22 self.build_description = jenkins_build_description23class BuildSourceData:24 def __init__(self, repository_name, sha):25 self.owner = repository_name.partition("/")[0]26 self.repo_short_name = repository_name.partition("/")[2]27 self.sha = sha28class BuildData:29 def __init__(self, build_source_data, build_jenkins_data):30 self.source_data = build_source_data31 self.jenkins_data = build_jenkins_data32class StatusData:33 def __init__(self, status, build_description = ""):34 self.status = status35 self.build_description = build_description36class OSRFBitbucketClient:37 def __init__(self, user, password):38 self.client = Client(39 BasicAuthenticator(40 user,41 password,42 'jrivero@osrfoundation.org'))43 self.status_str = ''44 @staticmethod45 def get_build_status_from_str(status):46 if status == 'ok':47 return BuildStatusStates.SUCCESSFUL48 elif status == 'failed':49 return BuildStatusStates.FAILED50 elif status == 'inprogress':51 return BuildStatusStates.INPROGRESS52 else:53 print("Invalid status: " + status)54 sys.exit(1)55 @staticmethod56 def build_data_from_file(config_file):57 stream = file(config_file, 'r')58 config = yaml.load(stream)59 bitbucket_origin = config['bitbucket_origin']60 src_data = config['jenkins_job']61 62 return BuildData(63 BuildSourceData(bitbucket_origin["repository_name"], 64 bitbucket_origin["sha"]),65 BuildJenkinsData(src_data["name"],66 src_data["url"]))67 def send_build_status(self, build_data, status_data):68 # Define key as the first 40 chars (bitbucket limit) of the 69 # job-name just after -ci-pr_any-. This should leave the70 # testing platform and architecture71 try:72 key = build_data.jenkins_data.job_name.split("-ci-pr_any-")[1][0:39]73 except: # fallback to use 40 first chars of job_name74 key = build_data.jenkins_data.job_name[0:39]75 build_status = BuildStatus.create_buildstatus(76 owner = build_data.source_data.owner,77 repository_name = build_data.source_data.repo_short_name,78 revision = build_data.source_data.sha,79 key = key,80 name = build_data.jenkins_data.build_name,81 url = build_data.jenkins_data.build_url,82 description = status_data.build_description,83 state = status_data.status,84 client = self.client)85 pprint(build_status)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful