From 3545a4765e4568f6bec2b52ad585b906f7a331e0 Mon Sep 17 00:00:00 2001 From: rachmadani haryono Date: Sat, 18 Mar 2017 22:09:09 +0800 Subject: [PATCH] Feature/retire test helpers (#131) * chg: test: merge test_helpers * chg: test: remove merged test helper. --- tests/test_buku.py | 59 +++++++++++++++++++++++++++++++++++++++- tests/test_helpers.py | 63 ------------------------------------------- 2 files changed, 58 insertions(+), 64 deletions(-) delete mode 100644 tests/test_helpers.py diff --git a/tests/test_buku.py b/tests/test_buku.py index 97cc7c3..3ced373 100644 --- a/tests/test_buku.py +++ b/tests/test_buku.py @@ -1,10 +1,15 @@ """test module.""" from itertools import product from unittest import mock +import os +import signal import sys +import unittest 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") @@ -290,7 +295,7 @@ def test_read_in(): assert res == message -def test_sigint_handler(): +def test_sigint_handler_with_mock(): """test func.""" with mock.patch('buku.os') as m_os: import buku @@ -422,3 +427,55 @@ def test_piped_input(argv, pipeargs, isatty): buku.piped_input(argv, pipeargs) return 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" diff --git a/tests/test_helpers.py b/tests/test_helpers.py deleted file mode 100644 index 74c376c..0000000 --- a/tests/test_helpers.py +++ /dev/null @@ -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()