Some corrections, to highlight the depth of my confusion...
On Nov 11, 2008, at 9:10 PM, Joe Strout wrote:
doctest.testmod (mymodule)
This actually works fine if I'm importing the module (with the
standard name) somewhere else
Actually, it does not.
I noticed that a function object has a __module__ attribute, that is
a reference to the module the function is in.
And no, it isn't; it's the NAME of the module the function is in. I'm
not sure what good that does me. docstring.testm od does take an
optional "name" parameter, but the documentation (at least in 2.5.2)
does not explain what this parameter is used for. I tried using it
thusly:
doctest.testmod (name=_test.__m odule__)
but that didn't work; it appears to still be testing the __main__
module. (Perhaps the name parameter is only used to describe the
module in the output, in which case, all I've accomplished here is
getting doctest to lie.)
I'm sure there is a magic identifier somewhere that lets a code get
a reference to its own module, but I haven't been able to find it.
Can someone share a clue?
This question remains open. :)
Thanks,
- Joe 2 1836
On Nov 12, 11:17*am, Joe Strout <j...@strout.ne twrote:
Some corrections, to highlight the depth of my confusion...
On Nov 11, 2008, at 9:10 PM, Joe Strout wrote:
* *doctest.testmo d(mymodule)
This actually works fine if I'm importing the module (with the *
standard name) somewhere else
Actually, it does not.
I noticed that a function object has a __module__ attribute, that is *
a reference to the module the function is in.
And no, it isn't; it's the NAME of the module the function is in. *I'm *
not sure what good that does me. *docstring.test mod does take an *
optional "name" parameter, but the documentation (at least in 2.5.2) *
does not explain what this parameter is used for. *I tried using it *
thusly:
* * * * doctest.testmod (name=_test.__m odule__)
but that didn't work; it appears to still be testing the __main__ *
module. *(Perhaps the name parameter is only used to describe the *
module in the output, in which case, all I've accomplished here is *
getting doctest to lie.)
I'm sure there is a magic identifier somewhere that lets a code get *
a reference to its own module, but I haven't been able to find it. *
Can someone share a clue?
This question remains open. *:)
Thanks,
- Joe
import sys
this_module = sys.modules[__name__]
sys.modules is a dictionary of all modules which have been imported
during the current session. Since the module had to be imported to
access it, it will be in there. '__name__' is available inside
functions because it is in the module scope.
Classes are a little more tricky because doing something like:
this_module = sys.modules[self.__class__. __module__]
will return a different module if the class is inherited in a
different module (since the base class is __class__ now). However,
putting a function at the module level (in the super-class module)
should anchor the results (untested though).
I'm not sure if this is the answer you need with regards to doctest,
but it I think it answers the question in the subject of this thread.
- Rafe
On Nov 11, 2008, at 9:49 PM, Rafe wrote:
>>I'm sure there is a magic identifier somewhere that lets a code get a reference to its own module, but I haven't been able to find it.
import sys
this_module = sys.modules[__name__]
Beautiful! Thanks very much. For the archives, here is my standard
module-testing idiom now:
def _test():
import doctest, sys
doctest.testmod (sys.modules[__name__])
if __name__ == "__main__":
_test()
Now, when I execute the module directly, it will test itself; and if I
need to test it from the outside (for example, under pdb) I can import
the module and then run themodule._test ().
To whom should I make the suggestion that this go into doctest docs?
Cheers,
- Joe This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my webserver runs that part of the
script (see attached file, snippet.php), though, it doesn't go through.
I don't get an error message or anything...it just returns a "1"
(whereas it should return a "0") as far as I can tell. I have read the
PHP...
|
by: Sean |
last post by:
Is there any way I could have the following work?
First I would have a module define a function to do
something like print some data.
----- module_name.py -----
def print_this(data):
|
by: Dennis |
last post by:
In my program I have defined a global vector with
//=======prototypes section ====================
float select(const int k, std::vector<float> &myArr, int iStart, int iEnd);
.....
//====Global Vectors ==================================
std::vector<float> gTmpArr(8000,0);
In Main, I would like to pass this vector to a function such as:
|
by: Bruce Lawrence |
last post by:
I'm running Access 97 and my modules are looping if someone puts an
invalid value in.
The setup:
3 macros - get_clock_num, verify_clocknum, append_to_history
3 functions. each in their own module - get_clocks(), verify_clocks(),
append()
Each macro runs a function from in its corresponding module.
Here is my code.
|
by: Ian Bicking |
last post by:
I got a puzzler for y'all. I want to allow the editing of functions
in-place. I won't go into the reason (it's for HTConsole --
http://blog.ianbicking.org/introducing-htconsole.html), except that I
really want to edit it all in-process and in-memory. So I want the
identity of the function to remain the same, even as I edit the body
and hopefully the signature too.
Well, the reason is that I want to edit any function object, without...
| |
by: rh0dium |
last post by:
Hi Experts!!
I am trying to get the following little snippet to push my data to the
function func(). What I would expect to happen is it to print out the
contents of a and loglevel. But it's not working. Can someone please
help me out.
---------<snip>--------------
#!/usr/bin/env python
|
by: bambam |
last post by:
import works in the main section of the module, but does
not work as I hoped when run inside a function.
That is, the modules import correctly, but are not visible to
the enclosing (global) scope.
Questions:
(1) Where can I read an explanation of this?
(2) Is there a work around?
|
by: RandomElle |
last post by:
Hi there
I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard...
|
by: Chadrik |
last post by:
i know how to programmatically create python functions:
module = __import__( '__main__')
def factory( val ):
def f( arg=val ): print arg, val
f.__name__ = 'function%s' % x
return f
for x in :
|
by: Steven D'Aprano |
last post by:
I have a function that needs a reference to the module object it is
defined in. (For the reason why, if you care, see the thread "doctest not
seeing any of my doc tests" from a week ago.) I know of two ways to deal
with this problem, both of which feel unsatisfactory to me. Assume the
name of the module is "Mod", then I can do either of these:
def foo():
import Mod
process(Mod)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |