You are viewing [info]binbrain's journal

Previous 10

Feb. 9th, 2011

Favorite recipe for dealing with loggers in test cases

Being able to on-the-fly setup your loggers is nice but can be painful for your test cases. Another use case is that you actually want to catch your loggers output from the code your testing. There lots of ways to solve this problem, but I find myself loving the below method


from code import Code
MockLog(list):
    def __getattr__(self, name):
        return self.append
Code.logger = MockLog()

def test_code():
    code.run()
    assert("Looking for this message to be logged by this point" in Code.logger)


How this works. In the Code class a logger will likely be set as an instance member. The above monkey patches that and when the instance tries to log the message with log.warning(msg) or log.error(msg) the message will just append to a list. I'm curious how folks without monkey patching at their disposal handle this?

Sep. 13th, 2010

building ctags with ptags.py

ctags will recurse into directories but doesn't properly identify defs, classes, etc... I found Python2.7/Tools/scripts/ptags.py which can build the tags file correctly. but it doesn't recurse into directories.

find . -name '*.py' | xargs ptags.py

Jun. 8th, 2010

Buildout a vanilla Zope 2.12 cluster

There doesn't seem to be a ZEO cluster buildout for Z2.12. This seems to work


[buildout]
zeo-address = 8100
inst1-address = 8080
inst2-address = 8081
debug-mode = off
parts  = zeo inst1 inst2

[zeo]
recipe = plone.recipe.zeoserver
zeo-address  = ${buildout:zeo-address}
zeo-log = ${buildout:directory}/var/zeoserver/zeoserver.log
pid-file = ${buildout:directory}/var/zeoserver/zeoserver.pid
socket-name = ${buildout:directory}/var/zeoserver/zeo.zdsock
blob-storage = ${buildout:directory}/var/zeoblobstorage/

[inst1]
recipe = plone.recipe.zope2instance
zeo-client = true
zeo-address = ${zeo:zeo-address}
user = admin:admin
debug-mode = ${buildout:debug-mode}
http-address = ${buildout:inst1-address}
event-log  = ${buildout:directory}/var/inst1/event.log
z2-log = ${buildout:directory}/var/inst1/Z2.log
pid-file = ${buildout:directory}/var/inst1/inst1.pid
lock-file = ${buildout:directory}/var/inst1/inst1.lock

[inst2]
recipe = collective.recipe.zope2cluster
instance-clone = inst1
http-address = ${buildout:inst2-address}

Apr. 22nd, 2010

gdata authsub token

I've been getting to know gdata auth a little lately. Well, I'm typically a fan of Google docs, the answer to how one might persist a user's session token evaded me initially. The answer is, after getting the authsuburl and upgrading the token, you must then get updated session token to store. That threw me off and a spent enough time figuring out that I felt it needed to be documented.

client = gdata.health.service.HealthService(source='yourCo-yourAppName-v1', use_h9_sandbox=True)
client.auth_token = single_use_token
client.UpgradeToSessionToken()
new_upgraded_token = client.GetAuthSubToken()

Dec. 30th, 2009

Registering SQLAlchemy as a Zope component utility

I recently ran into a problem with attempting to register a utility on a site in Zope2.12.

zope.sqlalchemy (ties SQLAlchemy into Zope transactions)
zope.localsitemanager (allows creation of Z3 like sites in Z2)

class ORMUtility(object)
    self.engine = create_engine("sqlite:///:memory", echo=True)
    self.Session = scoped_session(sessionmaker(bind=self.engine, extension=ZopeTransactionExtension()))


After using make_objectmanager_site to turn my Folder (ObjectManager) into a site, I was triggering a INewSiteEvent I was hooking it to register local utilities.

@adapter(INewSiteEvent)
def siteSetup(event):
    sm.registerUtility(ORMUtility())



This would throw an "can't pickle module objects". This error was discussed in a thread on the zope-dev mailing list. https://mail.zope.org/pipermail/zope-dev/2008-June/032019.html. To summarize, modules introduced in the ORMUtility class, create_engine and scoped_session don't support serialization.

I moved from zope.sqlalchemy to a package called z3c.saconfig. This allowed me register an EngineFactory safely. From what I can tell so far, this packages works like a charm in Zope2.12+Five dispite the z3c namespace.

Jul. 14th, 2009

ISO.org FTW

Researching a particular topic in healthcare led me to attempt to look up the ISO. Apparently, documents defining standards on the International Organization for Standardization website are not for free. How useless is that. I decided to add the document to my shopping cart for kicks. Anyone know how much 224,00 Swiss francs is in dollars.

Jul. 12th, 2009

Testing EHR standards compliance

Need to know if your EHR system meets HL7 standards for CCHIT certification? Check out Laika, an open source tool for testing compliance.

May. 27th, 2009

LaTex Beamer syntax highlighting

Finding it difficult to locate comprehensive documentation on syntax highlighting in Beamer I thought the intertubes could use an extra link.

http://en.wikibooks.org/wiki/LaTeX/Packages/Listings

Mar. 20th, 2009

Impressions of Google App Engine

I sat down last week and started tinkering with Google app engine for the first time. I'm impressed with the simplicity and speed I was able to get a functioning personal web site up and running for free. The unwanted ads are absent, and the URL is clean. Being able to add supporting libraries to the site is a feature I really appreciate. The site management features are nice as well. Most of all, the integration with Google services is something I'm looking forward to exploring.

So for now, welcome to my new home.

Oct. 1st, 2008

NY, NY "free" hotspots

So I'm cheap when it comes to my wifi. I expect when I pay for my $5 latte that my wifi access comes along with that, I'll probably order 2 by the time I leave, hence earning my free ride. Before moving to New York I anticipated New York to be a bustling hub of open access and am rather dejected now that I'm here to find that its not case. And being that I telecommute part of my week, I find myself doing a lot of extraneous exploring trying to find the free spots. They do exist, it takes some effort to find them though. For instance, the New York Public Libraries all have free access. Today I am at a nice little place in Greenwich Village that I found on my new favorite site listing free hotspots.

Previous 10

February 2011

S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728     

Syndicate

RSS Atom
Powered by LiveJournal.com