Feature/retire test helpers (#131)

* chg: test: merge test_helpers

* chg: test: remove merged test helper.
This commit is contained in:
rachmadani haryono 2017-03-18 22:09:09 +08:00 committed by Arun Prakash Jana
parent 8fc2775b48
commit 3545a4765e
2 changed files with 58 additions and 64 deletions

View File

@ -1,10 +1,15 @@
"""test module.""" """test module."""
from itertools import product from itertools import product
from unittest import mock from unittest import mock
import os
import signal
import sys import sys
import unittest
import pytest import pytest
from buku import is_int, parse_tags
only_python_3_5 = pytest.mark.skipif(sys.version_info < (3, 5), reason="requires python3.5") only_python_3_5 = pytest.mark.skipif(sys.version_info < (3, 5), reason="requires python3.5")
@ -290,7 +295,7 @@ def test_read_in():
assert res == message assert res == message
def test_sigint_handler(): def test_sigint_handler_with_mock():
"""test func.""" """test func."""
with mock.patch('buku.os') as m_os: with mock.patch('buku.os') as m_os:
import buku import buku
@ -422,3 +427,55 @@ def test_piped_input(argv, pipeargs, isatty):
buku.piped_input(argv, pipeargs) buku.piped_input(argv, pipeargs)
return return
buku.piped_input(argv, pipeargs) buku.piped_input(argv, pipeargs)
class TestHelpers(unittest.TestCase):
# @unittest.skip('skipping')
def test_parse_tags(self):
# call with None
parsed = parse_tags(None)
self.assertIsNone(parsed)
# call with empty list
parsed = parse_tags([])
self.assertEqual(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'))
# This test fails because we use os._exit() now
@unittest.skip('skipping')
def test_sigint_handler(capsys):
try:
# sending SIGINT to self
os.kill(os.getpid(), signal.SIGINT)
except SystemExit as error:
out, err = capsys.readouterr()
# assert exited with 1
assert error.args[0] == 1
# assert proper error message
assert out == ''
assert err == "\nInterrupted.\n"

View File

@ -1,63 +0,0 @@
#!/usr/bin/env python3
import os
import signal
import unittest
from buku import is_int, parse_tags
class TestHelpers(unittest.TestCase):
# @unittest.skip('skipping')
def test_parse_tags(self):
# call with None
parsed = parse_tags(None)
self.assertIsNone(parsed)
# call with empty list
parsed = parse_tags([])
self.assertEqual(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'))
# This test fails because we use os._exit() now
@unittest.skip('skipping')
def test_sigint_handler(capsys):
try:
# sending SIGINT to self
os.kill(os.getpid(), signal.SIGINT)
except SystemExit as error:
out, err = capsys.readouterr()
# assert exited with 1
assert error.args[0] == 1
# assert proper error message
assert out == ''
assert err == "\nInterrupted.\n"
if __name__ == "__main__":
unittest.main()