diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2016-07-28 16:06:15 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2016-08-05 10:45:02 -0700 |
commit | 450b95bce9bbdfc51d2074e15de49db7408a5750 (patch) | |
tree | 3c2262f00515385fe51d7795671f58c1406fe482 /unittests | |
parent | 24768559c45d2a7dcd38ccff7abf6de513d7cee8 (diff) |
unittests: port grouptools_tests to pytest
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/framework/test_grouptools.py | 132 | ||||
-rw-r--r-- | unittests/grouptools_tests.py | 130 |
2 files changed, 132 insertions, 130 deletions
diff --git a/unittests/framework/test_grouptools.py b/unittests/framework/test_grouptools.py new file mode 100644 index 000000000..f9262c755 --- /dev/null +++ b/unittests/framework/test_grouptools.py @@ -0,0 +1,132 @@ +# encoding=utf-8 +# Copyright © 2014, 2016 Intel Corporation + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +"""Module with tests for grouptools.""" + +from __future__ import ( + absolute_import, division, print_function, unicode_literals +) + +import pytest + +from framework import grouptools + +# pylint: disable=no-self-use + + +class TestJoin(object): + """Tests for the join function.""" + + def test_basic(self): + """grouptools.join: works correctly.""" + assert grouptools.join('g1', 'g2') == \ + grouptools.SEPARATOR.join(['g1', 'g2']) + + def test_no_trailing_separator(self): + """grouptools.join: doesn't add trailing separator with empty + element. + """ + test = grouptools.join('g1', 'g2', '') + assert not test.endswith(grouptools.SEPARATOR) + + def test_empty(self): + """grouptools.join: empty values are not joined""" + assert grouptools.join('', 'spec') == 'spec' + + +class TestSplit(object): + """tests for the split function.""" + + def test_basic(self): + assert grouptools.split(grouptools.join('g', 't')) == ['g', 't'] + + def test_input_empty(self): + """grouptools.split: an empty input returns [].""" + assert grouptools.split('') == [] + + +class TestFromPath(object): + """Tests for the from_path function.""" + + def test_nt(self): + """grouptools.from_path: converts \\ to separator in nt paths.""" + assert grouptools.from_path('foo\\bar') == grouptools.join('foo', 'bar') + + def test_posix(self): + """grouptools.from_path: converts / to separator in posix paths.""" + # Since we already have tests for grouptools.join we can trust it to do + # the right thing here. This also means that the test doesn't need to + # be updated if the separator is changed. + assert grouptools.from_path('foo/bar') == grouptools.join('foo', 'bar') + + def test_dot(self): + """grouptools.from_path: should convert '.' into ''.""" + assert grouptools.from_path('.') == '' + + +class TestCommonprefix(object): + """tests for the common prefix function.""" + + def test_empty(self): + """grouptools.commonprefix: handles an empty value""" + actual = grouptools.commonprefix((grouptools.join('foo', 'bar'), '')) + assert actual == '' + + def test_none(self): + """grouptools.commonprefix: returns '' when no values are the same""" + assert grouptools.commonprefix(['foo', 'bar']) == '' + + def test_basic(self): + expected = grouptools.commonprefix([grouptools.join('g1', 'g2', '1'), + grouptools.join('g1', 'g2', '2')]) + assert expected == grouptools.join('g1', 'g2') + + +class TestFormat(object): + """tests for the format function.""" + + def test_basic(self): + """grouptools.format: replaces grouptools.SEPARATOR with '/'""" + test_str = grouptools.SEPARATOR.join(['foo', 'bar', 'boink']) + assert grouptools.format(test_str) == 'foo/bar/boink' + + +class TestTestname(object): + """Tests for the testname function.""" + + def test_basic(self): + assert grouptools.testname(grouptools.join('g1', 'g2', 't1')) == 't1' + + +class TestGroupname(object): + """Tests for the groupname function.""" + + def test_basic(self): + assert grouptools.groupname(grouptools.join('g1', 'g2', 't1')) == \ + grouptools.join('g1', 'g2') + + +class TestSplitname(object): + """Tests for the splitname function.""" + + def test_basic(self): + assert grouptools.splitname(grouptools.join('g1', 'g2', 't1')) == \ + (grouptools.join('g1', 'g2'), 't1') diff --git a/unittests/grouptools_tests.py b/unittests/grouptools_tests.py deleted file mode 100644 index 9b52884f8..000000000 --- a/unittests/grouptools_tests.py +++ /dev/null @@ -1,130 +0,0 @@ -# Copyright (c) 2014 Intel Corporation - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -"""Module with tests for grouptools.""" - -from __future__ import ( - absolute_import, division, print_function, unicode_literals -) - -import nose.tools as nt - -import framework.grouptools as grouptools -from . import utils - -doc_formatter = utils.nose.DocFormatter({ # pylint: disable=invalid-name - 'separator': grouptools.SEPARATOR, -}) - - -@utils.nose.generator -def generate_tests(): - """Generate tests for the groups tools module. - - This cannot test all corners of the more complicated members. - - """ - data = [ - ('testname', grouptools.testname, grouptools.join('g1', 'g2', 't1'), - 't1'), - ('groupname', grouptools.groupname, grouptools.join('g1', 'g2', 't1'), - grouptools.join('g1', 'g2')), - ('splitname', grouptools.splitname, grouptools.join('g1', 'g2', 't1'), - (grouptools.join('g1', 'g2'), 't1')), - ('commonprefix', grouptools.commonprefix, - [grouptools.join('g1', 'g2', '1'), grouptools.join('g1', 'g2', '2')], - grouptools.join('g1', 'g2', '')), - ('split', grouptools.split, grouptools.join('g1', 'g2', 't1'), - ['g1', 'g2', 't1']), - ] - - test = lambda f, i, e: nt.assert_equal(f(i), e) - - for name, func, args, expect in data: - test.description = 'grouptools.{}: works'.format(name) - yield test, func, args, expect - - -def test_grouptools_join(): - """grouptools.join: works correctly.""" - # XXX: this hardcoded / needs to be fixed - nt.assert_equal(grouptools.join('g1', 'g2'), - grouptools.SEPARATOR.join(['g1', 'g2'])) - - -@doc_formatter -def test_grouptools_join_notrail(): - """grouptools.join: doesn't add trailing {separator} with empty element""" - test = grouptools.join('g1', 'g2', '') - nt.ok_(not test.endswith(grouptools.SEPARATOR)) - - -def test_split_input_empty(): - """grouptools.split: an empty input returns [].""" - nt.assert_equal(grouptools.split(''), []) - - -@doc_formatter -def test_from_path_posix(): - """grouptools.from_path: converts / to {separator} in posix paths.""" - # Since we already have tests for grouptools.join we can trust it to do the - # right thing here. This also means that the test doesn't need to be - # updated if the separator is changed. - nt.assert_equal(grouptools.from_path('foo/bar'), - grouptools.join('foo', 'bar')) - - -@doc_formatter -def test_from_path_nt(): - """grouptools.from_path: converts \\ to {separator} in nt paths.""" - nt.assert_equal(grouptools.from_path('foo\\bar'), - grouptools.join('foo', 'bar')) - - -def test_from_path_dot(): - """grouptools.from_path: should convert '.' into ''.""" - nt.assert_equal(grouptools.from_path('.'), '') - - -def test_commonprefix_empty(): - """grouptools.commonprefix: handles an empty value""" - expected = '' - value = grouptools.commonprefix((grouptools.join('foo', 'bar'), '')) - - nt.eq_(expected, value) - - -def test_join_empty(): - """grouptools.join: empty values are not joined""" - expected = 'spec' - test = grouptools.join('', 'spec') - nt.eq_(expected, test) - - -def test_commonprefix_none(): - """grouptools.commonprefix: returns '' when no values are the same""" - nt.eq_('', grouptools.commonprefix(['foo', 'bar'])) - - -@doc_formatter -def test_format(): - """grouptools.format: replaces {separator} with '/'""" - test_str = grouptools.SEPARATOR.join(['foo', 'bar', 'boink']) - nt.eq_(grouptools.format(test_str), 'foo/bar/boink') |