Re: Re: Re: porting unittest.py to Prothon.

"Mark Hahn" <[email protected]> Wed, 23 Jun 2004 10:50:03 -0700
Newsgroups gmane.comp.lang.prothon.devel
Message-ID <[email protected]>
Serge Orlov wrote:

> If the module is just a collection of functions like pyCompat
> or math, the ability to say "import all functions" is needed.

OK, I give in.  You win the argument.  It's on the to-do list.  I'm no match
for you in an argument. :-)

> the fix for bug 38 broke it, but here is the relevant code

I will debug with this code until it works again...

> name_ = "future"
> # work around for lack of globals()
> if isMain?():
>     myModule = Main
> else:
>     myModule = sys.modules.attrs_.get(Symbol(name_))

You can just say name_ = $future if you wish instead of using Symbol(name_).

>
> allExportNames = """AttributeError ImportError abs enumerate
> isinstance type""" allExportSymbols = [Symbol(name) for name in
> splitNames(allExportNames)]

Again you could have used [$AttributeError, $ImportError, ...

> def exportNames(namesStr):
>     """export names into caller's namespace
>
>     namesStr is a whitespace separated list of functions to export,
>     a special name * means export all functions.
>     """
>
>     namesList = splitNames(namesStr)
>     for name in namesList:
>         if name == "*":
>             symbolsToExport.extend!(allExportSymbols)
>             continue
>         symbol = Symbol(name)
>         if symbol not in allExportSymbols:
>             raise ImportError("module {name_} does not export symbol
>         {name}".fmt()) symbolsToExport.append!(symbol)
>     for symbol in symbolsToExport:
>         caller.attrs_[symbol] = myModule.attrs_[symbol]

Why does it make me feel good to see caller being used? :-)