Because of the mechanism for catching exceptions in pubs, the
UnexpectedInput exception raised by FakeInput never reached the catch
statement in the CommandTestCase and raised a FakeSystemExit instead.
This commit monkey-patches the exception handler in the ui at the same
time as the patching of the input functions to ignore UnexptectedInput
at the ui level.
This involved many changes, some side effects of the change include:
- remove of all `u"abc"` forms, in favor of
`from __future__ import unicode_literals`. Their usage was
inconsistent anyway, leading to problems when mixing with
unicode content.
- improve the tests, to allow printing for usecase even when
crashing. Should make future test easier. This is done with a
rather hacky `StdIO` class in `p3`, but it works.
- for some reason, the skipped test for Python 2 seems to work
now. While the previous point might seem related, it is not clear
that this is actually the case.
Current code version is added to the cache on writting. If the cache
version does not match the code version on read, the cache is ignored
which means it resets.
Added DOI regex function to utils.py which is called in add_cmd.py
upon specifying a new DOI. DOI validation applies directly on
argument parsing by using a custom argparse.Action.
Additionally, reverted FakeSystemExit subclassing Exception, but added
an explicit __init__ so that we can emulate the SystemExit.code
functionality without having to change the superclass.
Unittest just checks that both `pubs` and `pubs --help` raise a
`SystemExit` exception with error code 0. Due to how argparse
handles the `--help` keyword, this is the best way I could think to
provide test coverage without heavily modifying the parser structure
or the unittest infrastructure.
To ensure the `pubs` matches the behavior of `pubs --help`, it now
raises the same `SystemExit(0)` exception via `sys.exit(0)`. And
in order to catch it in the unittest, I had to modify the
`FakeSystemExit` behavior slightly.