Unit Testing and Test-Driven Development in Python

There are both advantages and disadvantages to being self-taught in any given discipline. In certain cases, the advantages and disadvantages can overlap or even coincide. For example, when you are self-taught, you are not confined by institutional structures and courses of study. On the one hand, this allows for a distinct measure of freedom to pursue one’s own interests in the field, which would not necessarily be afforded to a person following a traditional disciplinary curriculum. On the other hand, this also means that it can be quite easy to develop gaps in one’s basic knowledge of the discipline, for the simple reason that these areas of study did not fall within your area of interest.

I discovered one such gap in my study of programming in general, and Python in particular, a number of months ago when I came across a quote online that went something like this: “Code that is not tested is broken by definition.”  Testing? “You mean running the code to see if it works?” I thought to myself. Within the next hour I had my first exposure to the method of test-driven development and the Python unittest module.

This was literally the exact opposite of how I had approached my own programming projects up until then, which might be termed “error-driven development”: write some code; run it; see if it works; if it doesn’t work, tinker at random until it does; write some more code and repeat. I quickly realized that, according to the above quote, all my code was broken, by definition. 

The test-driven development model is the reverse of this: write a test, run it and watch it fail; write some code to make the test pass; refactor; write another test and repeat. It was an enlightening experience to attempt writing even a simple program under a test-driven model, as it was immediately obvious that I had only the vaguest notions about things that I thought I knew fairly well.

Since then, I’ve re-written a number of programs I’d created for myself under a completely test-driven developmental model, and have integrated testing into my everyday coding practice. I’ve also collected a bunch of resources that I've found helpful along the way, which you can find below. Also, as you may know, of late there has been something of a controversy brewing on the merit and value of test driven software development. Some links on this are supplied at the end. As always, further recommendations are welcome in the comments!

Overview of Test-Driven Development (Video Lectures)

Unit Testing in Python (Video Lectures)

Python Unittest Module Docs

Python Unittest Intro Tutorials

Test Driven Development in Python

Unit Testing Today

Congressional Vandals Blocked from Wikipedia

As the old saying goes, there is no distinctly criminal class in the United States, except for the Congress.  BBC reports that the US Congress IP address space has been banned from making edits on Wikipedia for repeated acts of intellectual dishonesty and digital vandalism.  Perhaps they should be arrested under the Computer Fraud and Abuse Act and sentenced to decades in prison.  Excerpt:
Wikipedia administrators have imposed a ban on page edits from computers at the US House of Representatives, following "persistent disruptive editing".
The 10-day block comes after anonymous changes were made to entries on politicians and businesses, as well as events like the Kennedy assassination . . .

Edits from computers using the IP address belonging to the House of Representatives have been banned before, following similar acts of vandalism . . . Jimmy Wales, the founder of Wikipedia, told the BBC that the incident did not surprise him, and vandalism has "always gone on and it always will".

Apple Responds to Claims of Backdoor in iOS Devices

 Just in case you were still wondering if your devices are secure.  From The Next Web:
Apple has published new information about the diagnostic capabilities of iOS, in what appears to be a response to suggestions that it includes a ‘backdoor’ that could enable governments and other third-parties to access user data.

The controversy arose after security consultant Jonathan Zdziarski documented a vulnerability that could leave usage data on iOS device exposed. Rebutting subsequent reports that linked the vulnerability with government data collection, Apple told iMore that it has “has never worked with any government agency from any country to create a backdoor in any of our products or services.” . . .

Following his initial findings, Zdziarski has been in contact with Apple. Citing the company’s response to his claims, he said that he “doesn’t buy for a minute that these services are intended solely for diagnostics.” That’s to say that he found the type of data available to the diagnostics services to be “of an extreme personal nature,” which seemed out of place given the focus.
For all you folks out there who "have nothing to hide", I suppose you have nothing to be afraid of.  But in that case, feel free to leave your bank account information in the comments!

Cryptography vs. Cryptanalysis: Black Hat Talk on Hacking Tor Pulled from Conference

Historians of cryptology often describe the development of the discipline of "secret writing" in terms of a dialectic between cryptography and cryptanalysis, that is, between code makers and code breakers.  Cryptographers seek to create ever more indecipherable encryption schemes and cryptanalysts seek to break them.  An article on the cancellation of a Black Hat conference talk on the Tor privacy service from Reuters provides us with an interesting glimpse of how this tension is currently playing out among hackers and security researchers within the US government.  From Reuters, on the cancelled talk:

A highly anticipated talk on how to identify users of the Internet privacy service Tor was withdrawn from the upcoming Black Hat security conference, a spokeswoman for the event said on Monday.

The talk was canceled at the request of attorneys for Carnegie Mellon University in Pittsburgh, where the speakers work as researchers, the spokeswoman, Meredith Corley, told Reuters . . . a Carnegie Mellon attorney informed Black Hat that one of the speakers could not give the Tor talk because the materials he would discuss have not been approved for public release by the university or the Software Engineering Institute (SEI). . . .

Its abstract, titled "You don't have to be the NSA to Break Tor: De-Anonymizing Users on a Budget," had attracted attention within the security and privacy communities. The abstract had been published on Black Hat's website but has since been removed.
While the media often identify Tor as the preferred browser of child pornographers, criminal cartels and terrorist groups they often fail to note that it was actually originally developed by US government researchers. Or perhaps their implication is that the US government naturally falls under one of those umbrella terms? Whatever the case may be in that regard, the Reuters article hints at the state of the arms race between US government cryptographers and cryptanalysts. Another excerpt:
The U.S. government funded the creation and much of the operation of Tor as a communications tool for dissidents in repressive countries. But Tor has frustrated the U.S. National Security Agency for years, according to documents released by former agency contractor Edward Snowden.
That revelation has helped increase adoption by those seeking privacy for political reasons, as well as criminals, researchers say. 
Some criminal suspects on Tor have been unmasked by the U.S. Federal Bureau of Investigation and other law enforcement or intelligence agencies using a variety of techniques, including tampering with software often used alongside Tor.

Check out the EFF for more information on Tor.

Space Station Sunday: Apollo 11 Anniversary Salute

***No Roses On The Moon Haiku***

RE: human life:
Planet Earth is Number One!
Let's start acting it.

Before the Space Station, there was the Eagle.  Happy 45th anniversary Apollo 11!

Freedom claims another victory.

Clutch! MIT Researchers Craft Extra Robotic Fingers (Even If You're Not Missing Any)

We may not be able to add more hours to our day or more nice days to summer, but now, we can add more digits to our hands.  MIT researchers have recently developed a system that allows even five-fingered folks to up their dexterity...with a little help from robotics.

Created by researcher Faye Wu, the "SR" or "supernumerary robotic" fingers are controlled by glove-embedded sensors which apply the same amount of grip and force as the rest of your hand.  The possibilities are intriguing...from folding laundry faster to executing literally unheard-of piano solos.  And the practical uses for those who need a little extra everyday help are diverse and ever-expanding.

As Wu said in a video interview posted on gizmodo.com, "The fingers are quite long, so the user can grab things that are usually much larger or much heavier than they can do with a single hand.  With the assistance of the SR fingers, users can grasp objects that are too difficult for them to do with a single hand.  For example, objects that are too large, too heavy, or the surface of the object is too hot or too cold.

You can also perform tasks that usually require two hands, for example, a single hand taking a cap off of a bottle, or opening a letter.  For elderly, or people with disabilities, these fingers can help them enjoy a living much more independently."

High five...no, high SEVEN to the researchers who continue to develop this project.

This is how the robot baristas are going to take over.