Simple Doc Test failing without any reason [Help Needed]

A

afrobeard

The following following code fails with the failiure:-


File "test.py", line 27, in __main__.sanitize_number
Failed example:
sanitize_number('0321-4683113')
Expected:
'03214683113'
Got:
'03214683113'


Expected and Got looks the same. The value should verify. What am I
doing wrong here ?

Thanks in advance. I really appreciate your time.

P.S. I tested this Python2.5 installed on both Ubuntu Hardy Heron and
Windows XP


/////////////////// Code /////////////////////////////////

import os;
import string;

def sanitize_number(input_number):
"""
Sanitize Number Module Please make Test Cases in Here
False


"""

countries = {
'92' : 'Pakistan'
}

"""
Reference http://en.wikipedia.org/wiki/List_of_mobile_codes_in_Pakistan
Please update original wiki article if more codes are
discovered
"""
providers = {
'300' : 'Mobilink',
'301' : 'Mobilink',
'302' : 'Mobilink',
'306' : 'Mobilink',
'307' : 'Mobilink',
'308' : 'Mobilink',
'309' : 'Mobilink',
'342' : 'Telenor',
'343' : 'Telenor',
'344' : 'Telenor',
'345' : 'Telenor',
'346' : 'Telenor',
'321' : 'Warid',
'322' : 'Warid',
'323' : 'Warid',
'331' : 'Ufone',
'332' : 'Ufone',
'333' : 'Ufone',
'334' : 'Ufone',
'313' : 'Zong',
'314' : 'Zong',
'320' : 'Instaphone',
'335' : 'SCOM'
}

#Rule 1 Numbers can only contain spaces, + and

input_number = string.join(input_number.split(), '') # Split
Spaces and join
input_number = string.join(input_number.split('-'),'') # Split
Spaces and join

#print "After Split Join", input_number

if input_number.startswith('00'):
input_number = input_number[2:]
elif input_number.startswith('0'):
input_number = input_number[1:]
elif input_number.startswith('+'):
input_number = input_number[1:]

#print "Phase1", input_number

#The number should now have either 10 or 12 digits depending on
whether or not country code is included

if len(input_number) == 10 or len(input_number) == 12:
if len(input_number) == 12:

for code in countries.keys():
if input_number.startswith(code):
input_number = input_number[2:]
break;
else:
return False # Country Code not Supported

for code in providers.keys():
if input_number.startswith(code):
#input_number = input_number[3:]
input_number = '0'+input_number
#print "Result", input_number
return input_number

return False

#print sanitize_number('+923214+683113') == False


def _test():
import doctest
doctest.testmod()

if __name__ == "__main__":
_test()
 
G

Gerard Flanagan

The following following code fails with the failiure:-

File "test.py", line 27, in __main__.sanitize_number
Failed example:
sanitize_number('0321-4683113')
Expected:
'03214683113'
Got:
'03214683113'

Expected and Got looks the same. The value should verify. What am I
doing wrong here ?

Thanks in advance. I really appreciate your time.

P.S. I tested this Python2.5 installed on both Ubuntu Hardy Heron and
Windows XP

Your code works for me (Python 2.5 WinXP).

Are you mixing tabs and spaces?

G.
 
A

afrobeard

I copied the text off here into a new file and it worked!.

I then took a diff between the version that didnt work and the version
that worked and the only difference was a couple of spaces after this
line:-

Apparently they caused the test case to fail on this.

Weird behavior :/

Thanks for your time Gerard and thanks to everyone else too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top