Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Run this example which illustrates unit testing using python's unittest module. Correct the problems with the code. Suppose that valid email addresses need to the

Run this example which illustrates unit testing using python's unittest module. Correct the problems with the code.

Suppose that valid email addresses need to the follow these rules:

- the address must contain one and only one @ character

- the string following the @ character MUST be abcSteel.com

- the string preceding the @ character must contain ONLY letters and optionally one period. It must be at least one letter.

filename: modValidateEmail.py

def isValidEmail(email): if email.count('@') != 1: #email address MUST aheve exactly one @ character return False tmpList = email.split('@') #create a list of 2 strings(username and mandated company name if len(tmpList) == 2: #there must be a username AND a company name return False

userName = tmpList[0] for c in userName: if not c.isalpha() and c!='.': return False inst=tmpList[1] if inst !='abcSteel.com': return False

image text in transcribed

#filename: UnitTestvalidEmail.py from unittest import * from modValidateEmail import* class TestvalidEmail(TestCase): #create a subclass of unittest's TestCase def testUserName(self): self.assertEqual (isValidEmail('joe4@abcSteel.com'),False) self.assertEqual(isValidEmail('joe$smith@abcSteel.com'),False) self.assertEqual (is ValidEmail('joe.allen.smith@abcSteel.com'),False) def testOneAmpersand(self): self.assertEqual(is ValidEmail('jim.'), False) self.assertEqual (isValidEmail(jim@smith@abcSteel.com'), False) def testCompany(self) self.assertEqual(isValidEmail('jim.smith@mnstate.com'), False) self.assertEqual(isValidEmail(jim.smith@abcStreel_com'),False) def testGoodEmail(self): self.assertEqual(isValidEmail('jesse.jones@abcSteel.com'),True) self.assertEqual(isValidEmail('jesse@abcSteel.com'), True) self.assertEqual(isValidEmail('jim.@abcSteel.com'),True) #main #unittest.ma.n() suite = TestLoader().loadTestsFromTestCase(TestvalidEmail) TextTestRunner(verbosity-2).run(suite) unittest

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions

Question

a. How do you think these stereotypes developed?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago