enqueue-fill-buffer: improve array formatting
[piglit.git] / unittests / framework / test_grouptools.py
blob77d63be666f3e8532736d2586e275726ae724c30
1 # encoding=utf-8
2 # Copyright © 2014, 2016, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
22 """Module with tests for grouptools."""
24 from __future__ import (
25 absolute_import, division, print_function, unicode_literals
28 import pytest
30 from framework import grouptools
32 # pylint: disable=no-self-use
35 class TestJoin(object):
36 """Tests for the join function."""
38 def test_basic(self):
39 """grouptools.join: works correctly."""
40 assert grouptools.join('g1', 'g2') == \
41 grouptools.SEPARATOR.join(['g1', 'g2'])
43 def test_no_trailing_separator(self):
44 """grouptools.join: doesn't add trailing separator with empty
45 element.
46 """
47 test = grouptools.join('g1', 'g2', '')
48 assert not test.endswith(grouptools.SEPARATOR)
50 def test_empty(self):
51 """grouptools.join: empty values are not joined"""
52 assert grouptools.join('', 'spec') == 'spec'
55 class TestSplit(object):
56 """tests for the split function."""
58 def test_basic(self):
59 assert grouptools.split(grouptools.join('g', 't')) == ['g', 't']
61 def test_input_empty(self):
62 """grouptools.split: an empty input returns []."""
63 assert grouptools.split('') == []
66 class TestFromPath(object):
67 """Tests for the from_path function."""
69 def test_nt(self):
70 """grouptools.from_path: converts \\ to separator in nt paths."""
71 assert grouptools.from_path('foo\\bar') == grouptools.join('foo', 'bar')
73 def test_posix(self):
74 """grouptools.from_path: converts / to separator in posix paths."""
75 # Since we already have tests for grouptools.join we can trust it to do
76 # the right thing here. This also means that the test doesn't need to
77 # be updated if the separator is changed.
78 assert grouptools.from_path('foo/bar') == grouptools.join('foo', 'bar')
80 def test_dot(self):
81 """grouptools.from_path: should convert '.' into ''."""
82 assert grouptools.from_path('.') == ''
85 class TestCommonprefix(object):
86 """tests for the common prefix function."""
88 def test_empty(self):
89 """grouptools.commonprefix: handles an empty value"""
90 actual = grouptools.commonprefix((grouptools.join('foo', 'bar'), ''))
91 assert actual == ''
93 def test_none(self):
94 """grouptools.commonprefix: returns '' when no values are the same"""
95 assert grouptools.commonprefix(['foo', 'bar']) == ''
97 def test_basic(self):
98 expected = grouptools.commonprefix([grouptools.join('g1', 'g2', '1'),
99 grouptools.join('g1', 'g2', '2')])
100 assert expected == grouptools.join('g1', 'g2')
103 class TestFormat(object):
104 """tests for the format function."""
106 def test_basic(self):
107 """grouptools.format: replaces grouptools.SEPARATOR with '/'"""
108 test_str = grouptools.SEPARATOR.join(['foo', 'bar', 'boink'])
109 assert grouptools.format(test_str) == 'foo/bar/boink'
112 class TestTestname(object):
113 """Tests for the testname function."""
115 def test_basic(self):
116 assert grouptools.testname(grouptools.join('g1', 'g2', 't1')) == 't1'
119 class TestGroupname(object):
120 """Tests for the groupname function."""
122 def test_basic(self):
123 assert grouptools.groupname(grouptools.join('g1', 'g2', 't1')) == \
124 grouptools.join('g1', 'g2')
127 class TestSplitname(object):
128 """Tests for the splitname function."""
130 def test_basic(self):
131 assert grouptools.splitname(grouptools.join('g1', 'g2', 't1')) == \
132 (grouptools.join('g1', 'g2'), 't1')