Best Python code snippet using hypothesis
regression_tester.py
Source: regression_tester.py
1#!/usr/bin/env python2"""Tool for checking if patch contains a regression test.3Pass in gerrit review number as parameter, tool will download branch and run4modified tests without bug fix.5"""6import string7import subprocess8import sys9gerrit_number = None10#TODO(jogo) use proper optParser11if len(sys.argv) == 2:12 gerrit_number = sys.argv[1]13else:14 gerrit_number = None15 print ("no gerrit review number specified, running on latest commit"16 "on current branch.")17def run(cmd, fail_ok=False):18 print "running: %s" % cmd19 try:20 rval = subprocess.check_output(cmd, shell=True)21 except subprocess.CalledProcessError:22 if not fail_ok:23 print "The command above terminated with an error."24 sys.exit(1)25 pass26 return rval27test_works = False28if gerrit_number:29 original_branch = run("git rev-parse --abbrev-ref HEAD")30 run("git review -d %s" % gerrit_number)31# run new tests with old code32run("git checkout HEAD^ nova")33run("git checkout HEAD nova/tests")34# identify which tests have changed35tests = run("git whatchanged --format=oneline -1 | grep \"nova/tests\" "36 "| cut -f2").split()37test_list = []38for test in tests:39 test_list.append(string.replace(test[0:-3], '/', '.'))40if test_list == []:41 test_works = False42 expect_failure = ""43else:44 # run new tests, expect them to fail45 expect_failure = run(("tox -epy27 %s 2>&1" % string.join(test_list)),46 fail_ok=True)47 if "FAILED (id=" in expect_failure:48 test_works = True49# cleanup50run("git checkout HEAD nova")51if gerrit_number:52 new_branch = run("git status | head -1 | cut -d ' ' -f 4")53 run("git checkout %s" % original_branch)54 run("git branch -D %s" % new_branch)55if test_works:56 print expect_failure57 print ""58 print "*******************************"59 print "FOUND a regression test"60else:61 print expect_failure62 print ""63 print "*******************************"64 print "NO regression test"...
test.py
Source: test.py
1import unittest2import petname3import petname.english4class TestAdjective(unittest.TestCase):5 def test_works(self):6 self.assertIn(petname.adjective(), petname.english.adjectives)7 def test_alias(self):8 self.assertIs(petname.adjective, petname.Adjective)9 def test_len(self):10 for l in range(4, 10):11 self.assertLessEqual(len(petname.adjective(l)), l)12class TestAdverb(unittest.TestCase):13 def test_works(self):14 self.assertIn(petname.adverb(), petname.english.adverbs)15 def test_alias(self):16 self.assertIs(petname.adverb, petname.Adverb)17 def test_len(self):18 for l in range(4, 10):19 self.assertLessEqual(len(petname.adverb(l)), l)20class TestName(unittest.TestCase):21 def test_works(self):22 self.assertIn(petname.name(), petname.english.names)23 def test_alias(self):24 self.assertIs(petname.name, petname.Name)25 def test_len(self):26 for l in range(4, 10):27 self.assertLessEqual(len(petname.name(l)), l)28class TestGenerate(unittest.TestCase):29 def test_works(self):30 words = 331 sep = '-'32 name = petname.generate(words, sep)33 self.assertEqual(len(name.split(sep)), words)34 def test_alias(self):35 self.assertIs(petname.generate, petname.Generate)36if __name__ == '__main__':...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
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!!