48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import imp, unittest
|
|
|
|
buku = imp.load_source('buku', '../buku')
|
|
|
|
from buku import parse_tags
|
|
from buku import *
|
|
|
|
|
|
class TestHelpers(unittest.TestCase):
|
|
|
|
# @unittest.skip('skipping')
|
|
def test_parse_tags(self):
|
|
# call without arguments
|
|
parsed = parse_tags()
|
|
self.assertIsNone(parsed)
|
|
# empty tags
|
|
parsed = parse_tags([",,,,,"])
|
|
self.assertEqual(parsed, ",")
|
|
# sorting tags
|
|
parsed = parse_tags(["z_tag,a_tag,n_tag"])
|
|
self.assertEqual(parsed, ",a_tag,n_tag,z_tag,")
|
|
# whitespaces
|
|
parsed = parse_tags([" a tag , , , ,\t,\n,\r,\x0b,\x0c"])
|
|
self.assertEqual(parsed, ",a tag,")
|
|
# duplicates, excessive spaces
|
|
parsed = parse_tags(["tag,tag, tag, tag,tag , tag "])
|
|
self.assertEqual(parsed, ",tag,")
|
|
# escaping quotes
|
|
parsed = parse_tags(["\"tag\",\'tag\',tag"])
|
|
self.assertEqual(parsed, ",\"tag\",\'tag\',tag,")
|
|
# combo
|
|
parsed = parse_tags([",,z_tag, a tag ,\t,,, ,n_tag ,n_tag, a_tag, \na tag ,\r, \"a_tag\""])
|
|
self.assertEqual(parsed, ",\"a_tag\",a tag,a_tag,n_tag,z_tag,")
|
|
|
|
# @unittest.skip('skipping')
|
|
def test_is_int(self):
|
|
self.assertTrue(is_int('0'))
|
|
self.assertTrue(is_int('1'))
|
|
self.assertTrue(is_int('-1'))
|
|
self.assertFalse(is_int(''))
|
|
self.assertFalse(is_int('one'))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|