forked from psyplot/psyplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.py
More file actions
66 lines (51 loc) · 2 KB
/
test_utils.py
File metadata and controls
66 lines (51 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Module for testing the :mod:`psyplot.utils` module."""
# Disclaimer
# ----------
#
# Copyright (C) 2021 Helmholtz-Zentrum Hereon
# Copyright (C) 2020-2021 Helmholtz-Zentrum Geesthacht
# Copyright (C) 2016-2021 University of Lausanne
#
# This file is part of psyplot and is released under the GNU LGPL-3.O license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3.0 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LGPL-3.0 license for more details.
#
# You should have received a copy of the GNU LGPL-3.0 license
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import _base_testing as bt
import unittest
import psyplot.utils as utils
class TestTempBool(unittest.TestCase):
"""Test the :class:`psyplot.utils._TempBool` class"""
def test_descriptor(self):
"""Test the descriptor functionality"""
class Test(object):
test = utils._temp_bool_prop('test')
t = Test()
self.assertFalse(t.test)
with t.test:
self.assertTrue(t.test)
t.test = True
self.assertTrue(t.test)
with t.test:
self.assertTrue(t.test)
del t.test
self.assertFalse(t.test)
class TestUniqueEverSeen(unittest.TestCase):
"""Test the :func:`psyplot.utils.unique_everseen` function"""
def test_simple(self):
self.assertEqual(list(utils.unique_everseen([1, 1, 2, 3, 4, 3])),
[1, 2, 3, 4])
def test_key(self):
self.assertEqual(list(utils.unique_everseen([1, 1, 2, 3, 4, 3],
key=lambda i: i % 3)),
[1, 2, 3])