November 1, 2011

how to add FindErr search to Google Chrome

As Internet becomes mainstream and stupid people start using it (perhaps "nontechnical" would be better in many contexts, but in this case I believe "stupid" is more accurate), services must cater to the needs of the stupid. That's what happened at Google, who, apparently around 2009, started to search for "what the user meant" instead of what the user actually told them to search.
Now, this might be helpful in many cases, but it just so happens that I'm smart enough to recognize when bad search results are my fault, and if I search for a term, I want the search engine to give me the results for that damn term.

The Plus operator used to do that - if you're looking for "FindErr" and not "finder", just type "+FindErr" and it will give you what you wish. Alas, not any more: because of Google+, plus operator is used to search for people on G+. Now, instead, you have to put quotes around the word. Baaaah.

So anyway, I'm not the only one who is unhappy about this, and some people have already taken action. That's what the FindErr.org search engine is about. You type a sane search string, and it makes it all quotey before passing on to Google. Now if only there was a way to make this search the default in Chrome (or Chromium), my favourite browser.

And there is. Follow these simple steps:
  1. type finderr.org into the address bar, and load the page
  2. right-click the URL
  3. choose "Edit Search engines"
  4. in the list, locate finderr.org and click "Set Default"
There! All done!

February 2, 2011

how to run the whole testsuite in a Python project/module

I can't believe Google doesn't have anything to say about this...

The situation is usual: you have a python module, let's call it bravo, and a set of unittest-based unit tests in bravo.test. Now, there's nothing like "runtest" or whatever to run the test suite. Of course, you could run each of the tests individually, but maybe there's twenty of them and you're lazy, or maybe they don't even contain the magical "if name=main then runtest" spell.

Twisted to the rescue! Just run this:
trial modulename
or
trial modulename.test

If you don't have Twisted (of which trial is a part), you can use the following snippet:


import glob, unittest, os, imp
suite = unittest.TestSuite()
testloader = unittest.TestLoader()

for test in glob.glob("bravo/tests/test_*.py"):
name = os.path.splitext(os.path.basename(test))[0]
module = imp.load_source(name, test)
tests = testloader.loadTestsFromModule(module)
suite.addTest(tests)

unittest.TextTestRunner().run(suite)