cctool

A tool for managing contacts and calendars.
git clone https://git.ce9e.org/cctool.git

commit
79cbd864d6608041d11d596e08d8d2dd695d8812
parent
dc5a2d06c3f10ac98ab65377ba137932de652044
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2015-04-11 07:42
add some tests

Diffstat

M cctool.py 1 -
A setup.cfg 13 +++++++++++++
A tests.py 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A tox.ini 16 ++++++++++++++++

4 files changed, 178 insertions, 1 deletions


diff --git a/cctool.py b/cctool.py

@@ -23,7 +23,6 @@
   23    23 # TODO
   24    24 # -	type conversion (especially dates)
   25    25 # -	filter/convert for valid fields
   26    -1 # -	tests
   27    26 # -	filter
   28    27 # -	merge when keys intercept (not necesserily equal)
   29    28 # -	abook needs no spaces between =

diff --git a/setup.cfg b/setup.cfg

@@ -0,0 +1,13 @@
   -1     1 [nosetests]
   -1     2 all-modules=1
   -1     3 with-doctest=1
   -1     4 with-coverage=1
   -1     5 cover-package=cctool
   -1     6 cover-erase=1
   -1     7 cover-branches=1
   -1     8 cover-html=1
   -1     9 cover-html-dir=.cover
   -1    10 
   -1    11 [flake8]
   -1    12 ignore=E101,W191,E126,E127,E128
   -1    13 exclude=.git,.tox,.env,build,dist,tests.py

diff --git a/tests.py b/tests.py

@@ -0,0 +1,149 @@
   -1     1 import unittest
   -1     2 from datetime import datetime
   -1     3 
   -1     4 import cctool
   -1     5 
   -1     6 dt = datetime(datetime.today().year, 1, 1)
   -1     7 
   -1     8 
   -1     9 class TestMultiDict(unittest.TestCase):
   -1    10 	def setUp(self):
   -1    11 		self.d = cctool.MultiDict()
   -1    12 
   -1    13 	def test_containes(self):
   -1    14 		self.assertFalse('foo' in self.d)
   -1    15 		self.d['foo'] = [1, 2, 3]
   -1    16 		self.assertTrue('foo' in self.d)
   -1    17 		self.d['foo'] = []
   -1    18 		self.assertFalse('foo' in self.d)
   -1    19 
   -1    20 	def test_get(self):
   -1    21 		self.assertEqual(self.d['foo'], [])
   -1    22 		self.d['foo'] = [1, 2, 3]
   -1    23 		self.assertEqual(self.d['foo'], [1, 2, 3])
   -1    24 
   -1    25 	def test_first(self):
   -1    26 		self.assertRaises(KeyError, self.d.first, 'foo')
   -1    27 		self.assertEqual(self.d.first('foo', default='bar'), 'bar')
   -1    28 		self.d['foo'] = [1, 2, 3]
   -1    29 		self.assertEqual(self.d.first('foo'), 1)
   -1    30 
   -1    31 	def test_join(self):
   -1    32 		self.d['foo'] = ['1', '2', '3']
   -1    33 		self.assertEqual(self.d.join('foo'), '1,2,3')
   -1    34 		self.assertEqual(self.d.join('bar', default='baz'), 'baz')
   -1    35 
   -1    36 	def test_update(self):
   -1    37 		self.d['foo'] = [1]
   -1    38 		self.d['bar'] = [1, 2]
   -1    39 
   -1    40 		md = cctool.MultiDict()
   -1    41 		md['foo'] = [2, 3]
   -1    42 		md['baz'] = [1, 2, 4]
   -1    43 
   -1    44 		self.d.update(md)
   -1    45 		self.assertEqual(self.d['foo'], [1, 2, 3])
   -1    46 		self.assertEqual(self.d['bar'], [1, 2])
   -1    47 		self.assertEqual(self.d['baz'], [1, 2, 4])
   -1    48 
   -1    49 
   -1    50 class TestMerged(unittest.TestCase):
   -1    51 	def test_merged(self):
   -1    52 		data = [
   -1    53 			cctool.MultiDict({'foo': [1], 'bar': [1, 2]}),
   -1    54 			cctool.MultiDict({'foo': [1], 'bar': [2, 3]}),
   -1    55 			cctool.MultiDict({'foo': [2], 'bar': [4]}),
   -1    56 			cctool.MultiDict({'bar': [5]}),
   -1    57 		]
   -1    58 		expected = [
   -1    59 			cctool.MultiDict({'foo': [1], 'bar': [1, 2, 3]}),
   -1    60 			cctool.MultiDict({'foo': [2], 'bar': [4]}),
   -1    61 			cctool.MultiDict({'bar': [5]}),
   -1    62 		]
   -1    63 		actual = cctool.merged(data, key='foo')
   -1    64 		for item in expected:
   -1    65 			self.assertIn(item, actual)
   -1    66 		for item in actual:
   -1    67 			self.assertIn(item, expected)
   -1    68 
   -1    69 
   -1    70 class _TestFormat(unittest.TestCase):
   -1    71 	data = [cctool.MultiDict({'name': ['foo']})]
   -1    72 
   -1    73 	def test_load(self):
   -1    74 		self.assertEqual(list(self.format.loads(self.text)), self.data)
   -1    75 
   -1    76 	def test_dump(self):
   -1    77 		self.assertEqual(self.format.dumps(self.data), self.text)
   -1    78 
   -1    79 
   -1    80 class TestBSDCal(_TestFormat):
   -1    81 	def setUp(self):
   -1    82 		self.format = cctool.BSDCal()
   -1    83 		self.data = [
   -1    84 			cctool.MultiDict({'dtstart': [dt], 'summary': ['foo']}),
   -1    85 			cctool.MultiDict({'bday': [dt], 'name': ['bar']}),
   -1    86 		]
   -1    87 		self.text = '01/01\tfoo\n01/01*\tbar\n'
   -1    88 
   -1    89 	def test_load(self):
   -1    90 		pass
   -1    91 
   -1    92 
   -1    93 @unittest.skipIf(isinstance(cctool.vobject, Exception), 'vobject not available')
   -1    94 class TestICal(_TestFormat):
   -1    95 	def setUp(self):
   -1    96 		self.format = cctool.ICal()
   -1    97 		self.data = [cctool.MultiDict({u'uid': [u'20140519T210153Z-13022@tobias-eee']})]
   -1    98 		self.text = 'BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//PYVOBJECT//NONSGML Version 1//EN\r\nBEGIN:VEVENT\r\nUID:20140519T210153Z-13022@tobias-eee\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n'
   -1    99 
   -1   100 
   -1   101 class TestABook(_TestFormat):
   -1   102 	def setUp(self):
   -1   103 		self.format = cctool.ABook()
   -1   104 		self.data = [cctool.MultiDict([
   -1   105 			('name', ['foo']),
   -1   106 			('bday', [datetime(1970, 1, 1)]),
   -1   107 		])]
   -1   108 		self.text = '[0]\nname = foo\nbday = 1970-01-01\n\n'
   -1   109 
   -1   110 
   -1   111 @unittest.skipIf(isinstance(cctool.ldif, Exception), 'ldif not available')
   -1   112 class TestLDIF(_TestFormat):
   -1   113 	def setUp(self):
   -1   114 		self.format = cctool.LDIF()
   -1   115 		self.data = [cctool.MultiDict({'dn': ['foo']})]
   -1   116 		self.text = '[0]\ndn = foo\n\n'
   -1   117 
   -1   118 	def test_dump(self):
   -1   119 		pass
   -1   120 
   -1   121 
   -1   122 @unittest.skipIf(isinstance(cctool.vobject, Exception), 'vobject not available')
   -1   123 class TestVCard(_TestFormat):
   -1   124 	def setUp(self):
   -1   125 		self.format = cctool.VCard()
   -1   126 		self.data = [cctool.MultiDict({
   -1   127 			u'version': [u'4.0'],
   -1   128 			u'fn': [u'Forrest Gump'],
   -1   129 			u'email': [u'forrestgump@example.com'],
   -1   130 			u'rev': [u'20080424T195243Z'],
   -1   131 		})]
   -1   132 		self.text = 'BEGIN:VCARD\nVERSION:4.0\nFN:Forrest Gump\nEMAIL:forrestgump@example.com\nREV:20080424T195243Z\nEND:VCARD'
   -1   133 
   -1   134 
   -1   135 class TestJSON(_TestFormat):
   -1   136 	def setUp(self):
   -1   137 		self.format = cctool.JSON()
   -1   138 		self.text = '[\n    {\n        "name": [\n            "foo"\n        ]\n    }\n]'
   -1   139 
   -1   140 
   -1   141 class TestArgs(unittest.TestCase):
   -1   142 	def test_args(self):
   -1   143 		args = cctool.parse_args(['-f', 'abook', '-t', 'bsdcal'])
   -1   144 		self.assertEqual(args.informat, 'abook')
   -1   145 		self.assertEqual(args.outformat, 'bsdcal')
   -1   146 
   -1   147 
   -1   148 if __name__ == '__main__':
   -1   149     unittest.main()

diff --git a/tox.ini b/tox.ini

@@ -0,0 +1,16 @@
   -1     1 # Tox (http://tox.testrun.org/) is a tool for running tests
   -1     2 # in multiple virtualenvs. This configuration file will run the
   -1     3 # test suite on all supported python versions. To use it, "pip install tox"
   -1     4 # and then run "tox" from this directory.
   -1     5 
   -1     6 [tox]
   -1     7 envlist = py27, py34, pypy
   -1     8 
   -1     9 [testenv]
   -1    10 commands =
   -1    11     flake8
   -1    12     nosetests
   -1    13 deps =
   -1    14     nose
   -1    15     coverage
   -1    16     flake8