Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
Convert doctest to TestCase class
Browse files Browse the repository at this point in the history
  • Loading branch information
l0b0 committed Feb 27, 2016
1 parent 03a87f2 commit 193e225
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
38 changes: 38 additions & 0 deletions tests/test_vcard_error.py
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from unittest import TestCase

from vcard.vcard_errors import VCardError


class TestVCardError(TestCase):
def test_empty_context_output(self):
actual = str(VCardError('message', {}))
expected = 'message'
self.assertEqual(expected, actual)

def test_single_context_item_output(self):
context = {'File': '/home/user/test.vcf'}
actual = str(VCardError('message', context))
expected = 'message\nFile: /home/user/test.vcf'
self.assertEqual(expected, actual)

def test_full_context_output(self):
context = {
'File': '/home/user/test.vcf',
'File line': 120,
'vCard line': 5,
'Property': 'ADR',
'Property line': 2,
'String': 'too;few;values;êéè'
}
actual = str(VCardError('message', context))
expected = '\n'.join([
'message',
'File: /home/user/test.vcf',
'File line: 120',
'vCard line: 5',
'Property: ADR',
'Property line: 2',
'String: too;few;values;êéè',
])
self.assertEqual(expected, actual)
33 changes: 0 additions & 33 deletions vcard/vcard_errors.py
Expand Up @@ -81,39 +81,6 @@ def __init__(self, message, context):
@param message: Error message
@param context: Dictionary with context information
Examples:
>>> raise VCardError('test', {})
Traceback (most recent call last):
VCardError: test
>>> raise VCardError('with path', {'File': '/home/user/test.vcf'})
Traceback (most recent call last):
VCardError: with path
File: /home/user/test.vcf
>>> raise VCardError('Error with lots of context', {
... 'File': '/home/user/test.vcf',
... 'File line': 120,
... 'vCard line': 5,
... 'Property': 'ADR',
... 'Property line': 2,
... 'String': 'too;few;values;êéè'})
Traceback (most recent call last):
VCardError: Error with lots of context
File: /home/user/test.vcf
File line: 120
vCard line: 5
Property: ADR
Property line: 2
String: too;few;values;êéè
>>> try:
... raise VCardError('test', {'Property': 'ADR'})
... except VCardError as error:
... error.context['File'] = '/home/user/test.vcf'
... raise VCardError(error.message, error.context)
Traceback (most recent call last):
VCardError: test
File: /home/user/test.vcf
Property: ADR
"""
Exception.__init__(self)
self.message = message
Expand Down

0 comments on commit 193e225

Please sign in to comment.