Some Python decorators

October 5th, 2009 by admin

import should

@ should.give ((5,2), 7)
@ should.give (( “aa”, “bbb”), “aabbb”)
@ should.give (([1], [2,3]), [1,2,3]),
@ should.give ((1,1), 1) # test
def add (a, b):
return a + b

@ should.throw ((1,0), Exception)
@ should.throw ((5,0), ZeroDivisionError)
@ should.throw ((5,0), TypeError) # test
@ should.throw ((5,1), TypeError) # test
def div (a, b):
return a / b

> pythonw-u “should.py”
[!] Add (1, 1) should give 1, but got 2.
[!] Div (5, 1) should raise TypeError, but raised nothing.
[!] Div (5, 0) should raise TypeError, but raised ZeroDivisionError.
> Exit code: 0

The idea is to describe the test cases to function as a decorator. Then they will perform a dual function:
Testing (automatic check at startup code after the change)
documentation (examples of functions)

Implementation:

# File: should.py

def render_func_args (f, args):
return ‘% s (% s)’% (f.__name__, ‘,’. join (map (repr, args)))

def _inform (msg):
print’[!]‘, msg

def should (args, expected):
def check (f):
val = f (* args)
if val! = expected:
_inform ( ‘% s should give% s, but got% s.’% \
(render_func_args (f, args), repr (expected), repr (val)))
def decor (f):
check (f)
return f

return decor

def should_raise (args, ExcptClass):
def check (f):
excpt = None
try:
f (* args)
except Exception, ex:
excpt = ex

if excpt == None:
_inform ( “% s should raise% s, but raised nothing.”% \
(render_func_args (f, args), ExcptClass.__name__))
elif not isinstance (excpt, ExcptClass):
_inform ( “% s should raise% s, but raised% s.”% \
(render_func_args (f, args), ExcptClass.__name__, excpt.__class__.__name__))
def decor (f):
check (f)
return f

return decor

throw = should_raise
give = should

if __name__ ==’__ main__ ‘:
import should

@ should.give ((5,2), 7)
@ should.give (( “aa”, “bbb”), “aabbb”)
@ should.give (([1], [2,3]), [1,2,3]),
@ should.give ((1,1), 1) # test
def add (a, b):
return a + b

@ should.throw ((1,0), Exception)
@ should.throw ((5,0), ZeroDivisionError)
@ should.throw ((5,0), TypeError) # test
@ should.throw ((5,1), TypeError) # test
def div (a, b):
return a / b

* This source code was highlighted with Source Code Highlighter.



Check out the analysis of indowebster.web.id, icicidirect.com, ddvip.com, maraton.com.tr, wn.com, emirates.com, ghacks.net, seagate.com, foxbusiness.com, sauto.cz - and much more

Nvidia Nexus

October 3rd, 2009 by admin

The company today unveiled nVidia nVidia Nexus - the industry’s first development environment for massively parallel computing, which is integrated into Microsoft Visual Studio - the most popular among developers environment for solutions based on Windows and Web applications.

«NVidia Nexus instantly increase the productivity of our programmers,” - commented Tarek El Dokor from the Edge 3 Technologies. “Integrated GPU / CPU solution for developers - this is what the Edge 3 needed a long time. Now, when this environment is integrated into Visual Studio, which we already use, it significantly reduces our time to study. ”

nVidia Nexus radically improves productivity with GPU-computing through the use of popular tools based on Microsoft Visual Studio and the working process in the “transparent” mode, without the need to create a separate version of the application to include a diagnostic program calls. NVidia Nexus technology also provides the ability to run code remotely on another computer. Nexus includes advanced tools for the simultaneous analysis of the effectiveness, efficiency and speed both graphically and CPU, so developers can immediately assess how the co-processing effect on their applications.

Nexus consists of three components:

Nexus Debugger - this is a debugger for source code GPU, such as the CUDA C, HLSL and DirectCompute. It supports source code control points, checkpoints, and data directly testing the memory of GPU. Debugging is fully carried out at the hardware level
Nexus Analyzer - a tool for performance tuning the system to view events GPU (core, API calls, data in memory) and events of CPU (the definition of kernel threads, processes and expectations) - all on one of the associated timeline
Nexus Graphics Inspector gives developers the opportunity to correct and profile shots, rendered using the API, such as Direct3D. Developers can use the Graphics Inspector to view the calls, textures, vertex buffers, and the state of API in the whole frame

Technology nVidia Nexus supports Windows 7 and Windows Vista and full integration with Visual Studio (2008 SP1 Standard Edition and later versions). BETA-version of nVidia Nexus will be available on October 15.


Check out the analysis of bangedclips.com, fok.nl, musicload.de, pia.jp, macromill.com, friendfinder.com, ksu.edu.sa, kozaczek.pl, guardian.co.uk, annunci69.it - and much more

Best image hosting solution

September 22nd, 2009 by admin

Take on you craving to upload crowded photos stow away a single perspicacity? Check out Pict photo hosting. Elaborate uploads, unlimited albums and swiftly servers is what I am speech about! Register double time at the largest comp photo and image hosting esteem internet.

MSI Wind Netbook review

September 17th, 2009 by admin

22 MSI Wind Netbook review
Launched a few months ago, Ultra MSI-of endurance Wind Netbook, namely: MSI Wind U110 ECO, which boasts a battery life up to nine o’clock is not impressive stamina, finally made it to the United States.

In terms of specifications in addition hardware and software to its ultra-endurance-Pack 9 cell battery, MSI Wind U110 ECO basically offers everything that we’ve seen before in standard U110 though without the double storage capacity (so you can forget about SSD) in coming up with Intel Atom Z530 processor Intel GMA500 graphics, 1GB of RAM and 160 GB hard drive under the hood while offering the same 10 “1024 x 600 (WSVGA) resolution display, a webcam, a 4-in-1 card reader and built-in wireless in the form of 802.11b / g (with Bluetooth and Draft N extra time).

JuicyCampus Dries Up

September 10th, 2009 by admin

We have short encyclopedia article with a fresh look on “JuicyCampus Dries Up” at the big IT blog TechCrunch. Writer thinks of a few tragic solutions & site creation books about “Another Day, Another Twitter Outage” (bluefame.com wiki), “Gmail Hitting Some Turbulence” (mp3raid.com profile), “Search Suggestions Come To Gmail (tripadvisor.fr profile)” and “Deny This, Last.fm (combats.com wiki)”. You may get tons of fresh crunch posts and summaries of amazing meetings.Online archives, services, news sites, media websites, startups, personal blogs are all represented inside “Deny This, Last.fm”. Have a good reading and bookmark us.

SpiralFrog Goes Belly Up

September 9th, 2009 by admin

Go through one post where author talks about “SpiralFrog Goes Belly Up” at the largest news blog TechCrunch. The author brings on some awesome topics and HTML problems related to “Jimmy Wales Deadpools Wikia Search” (babyblue100.com profile), “Behold! The Living Sasquatch” (21cn.com wiki), “Bing Travel Arrives (reed.co.uk wiki)” and “Updated: Social gambling site Pikum cashes in its chips and closes (gamesbannernet.com wiki)”. You can find megabytes of last year IT news & books about cool tech round tables.Online archives, personal blogs, startups, media websites, news sites, services are all featured inside “Live From Google I/O 2009″. Have a good reading and bookmark us.

Software and hardware perfect mix - Asus Eee PC

September 6th, 2009 by admin

25a Software and hardware perfect mix - Asus Eee PC

I think new Asus Eee PC is a great combo of portable Intel atom hardware and Windows XP software. With this little trip friend you may forget about all those big, old notebooks troubles and enjoy future bursting into preset though this small, easy to use gadget.

Geek Workspace

April 8th, 2009 by admin

Mini 9 on top of HP 15 / Deskspace

Xbox Cake funny photo

April 6th, 2009 by admin

Xbox Cake

Geek at Work

April 6th, 2009 by admin

92/365: Done?

« Previous Entries