2016-06-10 13:23:58 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2016-11-06 12:44:44 -06:00
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
import unittest
|
2016-06-10 13:23:58 -05:00
|
|
|
|
2016-11-06 12:44:44 -06:00
|
|
|
from buku import is_int, parse_tags
|
2016-06-10 13:23:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
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,")
|
|
|
|
|
2016-06-14 10:15:39 -05:00
|
|
|
# @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'))
|
|
|
|
|
2016-06-16 16:46:24 -05:00
|
|
|
|
|
|
|
def test_sigint_handler(capsys):
|
|
|
|
try:
|
|
|
|
# sending SIGINT to self
|
|
|
|
os.kill(os.getpid(), signal.SIGINT)
|
|
|
|
except SystemExit as error:
|
|
|
|
out, err = capsys.readouterr()
|
|
|
|
# assering exited with 1
|
|
|
|
assert error.args[0] == 1
|
|
|
|
# assering proper error message
|
|
|
|
assert out == ''
|
|
|
|
assert err == "\nInterrupted.\n"
|
|
|
|
|
2016-06-10 13:23:58 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|