]> git.arvados.org - arvados.git/blob - sdk/python/tests/test_internal.py
22581: Add ContainerWebServices to config
[arvados.git] / sdk / python / tests / test_internal.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import re
6
7 import pytest
8
9 from arvados import _internal
10
11 class TestDeprecated:
12     @staticmethod
13     @_internal.deprecated('TestVersion', 'arvados.noop')
14     def noop_func():
15         """Do nothing
16
17         This function returns None.
18         """
19
20     @pytest.mark.parametrize('pattern', [
21         r'^Do nothing$',
22         r'^ *.. WARNING:: Deprecated$',
23         r' removed in Arvados TestVersion\.',
24         r' Prefer arvados\.noop\b',
25         r'^ *This function returns None\.$',
26     ])
27     def test_docstring(self, pattern):
28         assert re.search(pattern, self.noop_func.__doc__, re.MULTILINE) is not None
29
30     def test_deprecation_warning(self):
31         with pytest.warns(DeprecationWarning) as check:
32             self.noop_func()
33         actual = str(check[0].message)
34         assert ' removed in Arvados TestVersion.' in actual
35         assert ' Prefer arvados.noop ' in actual
36
37
38 class TestParseSeq:
39     @pytest.mark.parametrize('s', [
40         'foo,bar',
41         'foo, bar',
42         'foo , bar',
43     ])
44     def test_default_split(self, s):
45         assert list(_internal.parse_seq(s)) == ['foo', 'bar']
46
47     @pytest.mark.parametrize('s', [
48         'foo',
49         ',foo',
50         'foo ,',
51         ' foo ',
52         ',foo,',
53         ', foo ,',
54     ])
55     def test_empty_filtering(self, s):
56         assert list(_internal.parse_seq(s)) == ['foo']
57
58     @pytest.mark.parametrize('s', [
59         '',
60         ' ',
61         ',',
62         ' , ',
63     ])
64     def test_empty_list(self, s):
65         assert list(_internal.parse_seq(s)) == []
66
67
68 class TestUniq:
69     @pytest.mark.parametrize('arg', [
70         'abcde',
71         'aabbccddee',
72         'abcdeabcde',
73         'ababcbabcdcbabcdedcbae',
74     ])
75     def test_uniq(self, arg):
76         assert list(_internal.uniq(iter(arg))) == list('abcde')