From 352d1686876020e93f8f51cc7370daa1af576c5d 2016-02-27 11:05:34 From: Lance Edgar Date: 2016-02-27 11:05:34 Subject: [PATCH] Fix some tests. --- diff --git a/rattail/exceptions.py b/rattail/exceptions.py index 82ff34f0d51bc5f477149e3f25ee9f3dffeaf030..f54f7ab6ea58f6b8fa16d0a728acda60337fe58b 100644 --- a/rattail/exceptions.py +++ b/rattail/exceptions.py @@ -26,7 +26,7 @@ This module contains all core Rattail exception classes. """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import class RattailError(Exception): @@ -34,9 +34,6 @@ class RattailError(Exception): Base class for all Rattail exceptions. """ - def __str__(self): - return unicode(self).encode('utf_8') - class ConfigurationError(RattailError): """ @@ -118,9 +115,6 @@ class PathNotFound(FileOperationError): def __init__(self, original_error): self.original_error = original_error - def __str__(self): - return unicode(self).encode('utf_8') - def __unicode__(self): return '{0}: {1}'.format( self.original_error.__class__.__name__, @@ -138,8 +132,8 @@ class BatchTypeNotFound(BatchError): def __init__(self, name): self.name = name - def __str__(self): - return "Batch type not found: %s" % self.name + def __unicode__(self): + return "Batch type not found: {}".format(self.name) class BatchTypeNotSupported(BatchError): @@ -152,8 +146,8 @@ class BatchTypeNotSupported(BatchError): self.executor = executor self.batch_type = batch_type - def __str__(self): - return "Batch type '%s' is not supported by executor: %s" % ( + def __unicode__(self): + return "Batch type '{}' is not supported by executor: {}".format( self.batch_type, repr(self.executor)) @@ -162,8 +156,8 @@ class BatchExecutorNotFound(BatchError): def __init__(self, name): self.name = name - def __str__(self): - return "Batch executor not found: %s" % self.name + def __unicode__(self): + return "Batch executor not found: {}".format(self.name) class LabelPrintingError(Exception): @@ -179,7 +173,7 @@ class PalmError(RattailError): class PalmClassicDatabaseTypelibNotFound(PalmError): - def __str__(self): + def __unicode__(self): return ("The Python module for the Palm Classic Database type library " "could not be generated. (Is the HotSync Manager software " "installed?)") @@ -187,18 +181,18 @@ class PalmClassicDatabaseTypelibNotFound(PalmError): class PalmConduitManagerNotFound(PalmError): - def __str__(self): + def __unicode__(self): return ("The Palm Desktop Conduit Manager could not be instantiated. " "(Is the HotSync Manager software installed?)") class PalmConduitAlreadyRegistered(PalmError): - def __str__(self): + def __unicode__(self): return "The Rattail Palm conduit is already registered." class PalmConduitNotRegistered(PalmError): - def __str__(self): + def __unicode__(self): return "The Rattail Palm conduit is not registered." diff --git a/tests/test_commands.py b/tests/test_commands.py index 73371a27eca81d35fc0e5893bf89c6c7a72c1a70..d1f363566a0fbb3a4fff6a4349bc4df48dd8b8bb 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import import csv import datetime @@ -17,6 +17,7 @@ from sqlalchemy import func from . import DataTestCase from rattail import commands +from rattail.commands.core import ArgumentParser, date_argument from rattail.db import Session from rattail.db import model from rattail.db.auth import authenticate_user @@ -25,7 +26,7 @@ from rattail.db.auth import authenticate_user class TestArgumentParser(TestCase): def test_parse_args_preserves_extra_argv(self): - parser = commands.ArgumentParser() + parser = ArgumentParser() parser.add_argument('--some-optional-arg') parser.add_argument('some_required_arg') args = parser.parse_args([ @@ -39,11 +40,11 @@ class TestArgumentParser(TestCase): class TestDateArgument(TestCase): def test_valid_date_string_returns_date_object(self): - date = commands.date_argument('2014-01-01') + date = date_argument('2014-01-01') self.assertEqual(date, datetime.date(2014, 1, 1)) def test_invalid_date_string_raises_error(self): - self.assertRaises(argparse.ArgumentTypeError, commands.date_argument, 'invalid-date') + self.assertRaises(argparse.ArgumentTypeError, date_argument, 'invalid-date') class TestCommand(TestCase): @@ -184,7 +185,7 @@ class TestAddUser(DataTestCase): def test_no_user_created_if_password_prompt_is_canceled(self): self.assertEqual(self.session.query(model.User).count(), 0) - with patch('rattail.commands.getpass') as getpass: + with patch('rattail.commands.core.getpass') as getpass: getpass.side_effect = KeyboardInterrupt commands.main('adduser', '--no-init', '--stderr', self.stderr_path, 'fred') with open(self.stderr_path) as f: @@ -193,7 +194,7 @@ class TestAddUser(DataTestCase): def test_normal_user_created_with_correct_password_but_no_admin_role(self): self.assertEqual(self.session.query(model.User).count(), 0) - with patch('rattail.commands.getpass') as getpass: + with patch('rattail.commands.core.getpass') as getpass: getpass.return_value = 'fredpass' commands.main('adduser', '--no-init', '--stdout', self.stdout_path, 'fred') with open(self.stdout_path) as f: @@ -206,7 +207,7 @@ class TestAddUser(DataTestCase): def test_admin_user_created_with_administrator_role(self): self.assertEqual(self.session.query(model.User).count(), 0) - with patch('rattail.commands.getpass') as getpass: + with patch('rattail.commands.core.getpass') as getpass: getpass.return_value = 'fredpass' commands.main('adduser', '--no-init', '--stdout', self.stdout_path, 'fred', '--administrator') fred = self.session.query(model.User).one()