From fb1f397fee00daa9197021d99df639a67e195f6c Mon Sep 17 00:00:00 2001 From: William Ting Date: Tue, 31 Dec 2013 16:34:35 -0600 Subject: [PATCH] add string unit tests --- Makefile | 3 +++ bin/autojump_utils.py | 2 +- tests/autojump_utils_test.py | 22 ++++++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 24b201d..cf832e1 100644 --- a/Makefile +++ b/Makefile @@ -37,3 +37,6 @@ tar: # Create tagged archive git archive --format=tar --prefix autojump_v$(VERSION)/ $(TAGNAME) | gzip > autojump_v$(VERSION).tar.gz sha1sum autojump_v$(VERSION).tar.gz + +test: + testify -v tests diff --git a/bin/autojump_utils.py b/bin/autojump_utils.py index b8fee4a..d040e95 100644 --- a/bin/autojump_utils.py +++ b/bin/autojump_utils.py @@ -174,7 +174,7 @@ def print_tab_menu(needle, tab_entries, separator): def sanitize(directories): - clean = lambda x: decode(x).rstrip(os.sep) + clean = lambda x: decode(x) if len(x) == 1 else decode(x).rstrip(os.sep) return list(imap(clean, directories)) diff --git a/tests/autojump_utils_test.py b/tests/autojump_utils_test.py index 0d9a442..9ffd4c8 100644 --- a/tests/autojump_utils_test.py +++ b/tests/autojump_utils_test.py @@ -1,11 +1,17 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- -from testify import * +import mock +from testify import TestCase +from testify import assert_equal +from testify import run +import autojump_utils from autojump_utils import decode from autojump_utils import first -from autojump_utils import second from autojump_utils import last +from autojump_utils import sanitize +from autojump_utils import second +from autojump_utils import surround_quotes from autojump_utils import take @@ -14,6 +20,18 @@ class StringTestCase(TestCase): assert_equal(decode(r'blah'), u'blah') assert_equal(decode(r'日本語'), u'日本語') + @mock.patch.object(autojump_utils, 'in_bash', return_value=True) + def test_surround_quotes_in_bash(self, _): + assert_equal(surround_quotes('foo'), '"foo"') + + @mock.patch.object(autojump_utils, 'in_bash', return_value=False) + def test_dont_surround_quotes_not_in_bash(self, _): + assert_equal(surround_quotes('foo'), 'foo') + + def test_sanitize(self): + assert_equal(sanitize([]), []) + assert_equal(sanitize([r'/foo/bar/', r'/']), [u'/foo/bar', u'/']) + class IterationTestCase(TestCase): def test_first(self):