Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to import only one module in a package when the package__init__.py has already imports the modules?

Reply
Thread Tools

How to import only one module in a package when the package__init__.py has already imports the modules?

 
 
Steven D'Aprano
Guest
Posts: n/a
 
      11-01-2009
On Sun, 01 Nov 2009 08:07:37 -0600, Peng Yu wrote:

> It is
> reasonable to assume the log of the number of states of a function or a
> class is proportional to it length. Hence, when a function or a
> class is long, you will never be able to test all its states.




def f(n):
return n + 5


def g(n):
x = n + 1
x += 1
x += 1
x += 1
return x + 1


Function g() has five times the length (in lines) as f(). Does it require
five times the testing? Obviously not. In fact, there's no easy way to
test the internal state of the function from outside, because x is local
to g(). You can't test the value of x from outside, because x is not
exposed to the outside.

The complexity of testing functions is roughly proportional to the number
of paths through the function, not the number of lines. Both f() and g()
have a single path through the function and therefore require the same
amount of testing.

The simplest estimate of the number of paths in a function is the number
of if...else statements. Each pair *doubles* the number of paths:

def func():
if cond1: A
else: B
if cond2: C
else: D
if cond3: E
else: F

There are 2**3 paths that need testing:

ACE ACF ADE ADF BCE BCF BDE BDF


Or consider this example:

def func(x, cond):
for f in [A, B, C, D, E, F]:
if cond(x): x = f(x)


This function has two lines only, but clearly there could be as many as
128 paths that need testing. Ideally your test data should visit each one
of these paths.



--
Steven
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Package that imports with name of dependent package David Pratt Python 4 05-13-2006 05:12 PM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:08 PM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:01 PM
package module import name clash with global package George P Python 3 09-11-2004 01:19 PM



Advertisments