Tuesday, March 6, 2012

py.test paremeterized test fails with "LookupError: no factory found for function argument …"


I have a trivial test:
import pytest
@pytest.mark.parameterize(("input", "expected"), [
    ("3+5", 8),
    ("2+4", 6),
    ("6*9", 42),
])
def test_eval(input, expected):
    assert eval(input) == expected
It fails saying:
LookupError: no factory found for function argument 'input'
available funcargs: pytestconfig, capsys, capfd, tmpdir, monkeypatch, recwarn
use 'py.test --funcargs [testpath]' for help on them.
What's going on here? It's spelt parametrize – not parameterize.

But why didn't I get a NameError?

pytest.mark allows arbitrary marks to be added to a function. Due to the
dynamic nature of py.test, pytest.mark.<any name here> can be used to mark a
test. Since pytest.mark.parameterize isn't recognised by any of the pytest
plugins, it's essentially a no-op.

Monday, March 5, 2012

Problem cloning local git repository using `git clone file:///…`

So I was trying to clone a local git repository using:
$ git clone file:///home/git/repositories/bar.git
And I would get output like this:
$ git clone file:///home/git/repositories/bar.git/ bar
Initialized empty Git repository in /home/brad/bar/.git
remote: Counting objects: 1317, done.
remote: Compressing objects: 100% (1179/1179), done.
remote: Total 1317 (delta 601), reused 406 (delta 57)
Receiving objects: 100% (1317/1317), 5.37 MiB | 683 KiB/s, done.
Resolving deltas: 100% (601/601), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.
The issue was that although I had added myself to the git group, the permissions on the heads refs did not permit group read:
$ ls -lha /home/git/repositories/bar.git/refs/heads
total 12K
drwx------ 2 git git 4.0K 2012-03-05 15:42 .
drwx------ 4 git git 4.0K 2012-02-28 14:21 ..
-rw------- 1 git git   41 2012-03-05 15:45 development
-rw------- 1 git git   41 2012-03-05 15:42 master
Simple fix:
$ chmod g+r /home/git/repositories/bar.git/refs/heads/*
So why was this suddenly a problem?

It just so happens I recently upgraded from gitosis to gitolite, and gitolite uses a different umask (0077) to gitosis. This means that every new file created was created with only user permissions.

I want g+rx, so I edited /home/git/.gitolite.rc and changed $REPO_UMASK to 0027.


Saturday, February 18, 2012

Remove items from print spool/queue in Windows 7

I've recently had some trouble deleting/removing a print job/item from the printer spool/queue on Windows 7. The print job just wouldn't delete despite rebooting and instructing Windows to delete it many times. After a bit of googling I found a solution:

  1. Open a command window (Click Start; Type command and press enter)
  2. Right click the title bar and select "Run as Administrator"
  3. Type net stop spooler and press enter.
  4. Type del %systemroot%\System32\spool\printers\* /Q and press enter.
  5. Type net start spooler and press enter.

Sunday, January 22, 2012

Install Upstart 1.3 on Ubuntu 10.04

I wanted to upgrade Upstart on Ubuntu 10.04 to make use of the new user jobs feature.  I cherry picked packages from Ubuntu 11.10 via http://pkgs.org/ubuntu-11.10/ubuntu-main-amd64/ . Here's what I came up with: (Run each command separately, some require user input) I found that dbus wasn't installed, and as such running start foo would fail:

$ start foo
start: Unable to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory


Fixed via sudo apt-get install dbus

Wednesday, December 14, 2011

Using ReportLab to create a PDF from an image.

If you want to create a page in a PDF that contains an image that fills the entire page, here's a snippet that'll do exactly that. It requires PIL and ReportLab. Simply pass the function the path to an image and the canvas, and it'll fill the current page with the image (rotated properly including honoring EXIF orientation attributes).

Due to it handling EXIF orientation values, it's compatible with images taken from the camera of iPhone and iPad devices.

Wednesday, November 16, 2011

Another strange Django error

If you stumble across the error in Django 1.3:

  ...
  File "/Users/brad/work/django-formwizard/.env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 368, in reverse
    app_list = resolver.app_dict[ns]
  File "/Users/brad/work/django-formwizard/.env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 241, in _get_app_dict
    self._populate()
  File "/Users/brad/work/django-formwizard/.env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 198, in _populate
    p_pattern = pattern.regex.pattern
AttributeError: 'str' object has no attribute 'regex'


Or in Django 1.4:


...

  File "/brew/Cellar/python/2.7.1/lib/python2.7/site-packages/django/core/handlers/base.py", line 101, in get_response
    request.path_info)
  File "/brew/Cellar/python/2.7.1/lib/python2.7/site-packages/django/core/urlresolvers.py", line 300, in resolve
    sub_match = pattern.resolve(new_path)
AttributeError: 'str' object has no attribute 'resolve'



You have probably accidentally left a trailing comma in the URLCONF_ROOT setting, i.e.:


ROOT_URLCONF = 'project.urls',

Sunday, November 13, 2011

Strange UTF-8 decoding error with Jenkins + Python

I've come across a strange problem while setting up Jenkins to build Python projects. For some reason I get the following error:


Traceback (most recent call last):
  File "setup.py", line 32, in <module>
    'Topic :: Software Development :: Libraries :: Python Modules',
  File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  ...

  File "/home/jenkins/.jenkins/jobs/django-console/workspace/django_attest-0.1.1-py2.7.egg/django_attest/__init__.py", line 0
SyntaxError: 'NoneType' object has no attribute 'utf_8_decode'

In any case it's fixed by adding the following as an environment variable (I added it to the Properties Content section):
LANG=en_AU.UTF-8