473,287 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Simple Doc Test failing without any reason [Help Needed]

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
>>sanitize_number('0321-4683113')
'03214683113'
>>sanitize_number('03214683113')
'03214683113'
>>sanitize_number('0321-468-3113')
'03214683113'
>>sanitize_number('0321 4683113')
'03214683113'
>>sanitize_number('0321 468 3113')
'03214683113'
>>sanitize_number('3214683113')
'03214683113'
>>sanitize_number('923214683113')
'03214683113'
>>sanitize_number('00923214683113')
'03214683113'
>>sanitize_number('+923214683113')
'03214683113'
>>sanitize_number('+923214+683113')
False
"""

countries = {
'92' : 'Pakistan'
}

"""
Reference http://en.wikipedia.org/wiki/List_of...es_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()
Jun 27 '08 #1
3 1213
On May 28, 1:48 pm, afrobeard <afrobe...@gmail.comwrote:
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.

Jun 27 '08 #2
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:-
>>sanitize_number('0321-4683113')<There were some spaces in these angle brackets>
Apparently they caused the test case to fail on this.

Weird behavior :/

Thanks for your time Gerard and thanks to everyone else too.
On May 28, 5:11*pm, Gerard Flanagan <grflana...@gmail.comwrote:
On May 28, 1:48 pm, afrobeard <afrobe...@gmail.comwrote:
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.
Jun 27 '08 #3
afrobeard <af*******@gmail.comwrites:
>sanitize_number('0321-4683113')<There were some spaces in these angle brackets>

Apparently they caused the test case to fail on this.

Weird behavior :/
Nope, exactly as specified: doctest is reporting differences berween
what output was generated and what output you described.
Thanks for your time Gerard and thanks to everyone else too.
Moral of the story: Configure your editor to highlight trailing space
on a line as an error, and always remove it before saving a program
source code file.

--
\ “Men never do evil so completely and cheerfully as when they |
`\ do it from religious conviction.” —Blaise Pascal |
_o__) (1623-1662), Pensées, #894. |
Ben Finney
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stephanie Stowe | last post by:
Hi. I read in some helpful publication "If a cookie created by a page on catalog.acme.com sets its path attribute to "/" and its domain attrinute to "acme.com", that cookie is available to all...
4
by: frank | last post by:
I posted a question before (to too many groups) and this time I am sending to this group only. I have a quick script as seen below, the file_list table has a unique field called file_name. The...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
4
by: bob lambert | last post by:
Help I am trying to deploy to another pc a vb.net std 2002 windows form application. I am confused. I created a project - windows form I built form, compiled and debugged. I created a...
18
by: Scott David Daniels | last post by:
There has been a bit of discussion about a way of providing test cases in a test suite that _should_ work but don't. One of the rules has been the test suite should be runnable and silent at every...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
0
DressageRider
by: DressageRider | last post by:
I need your help. Desperately. Someone has to be able to fix the utter balls up I've made after dinking around in Flash for the last four days. I have no prior knowledge of anything other than...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
55
by: copx | last post by:
Can anyone point me to a simple, fast RRNG function to generate random ints within a specified range? It is important that each value within the range has the same probability (uniform...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.