473,399 Members | 4,177 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,399 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 1218
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.