File: test_util.py

package info (click to toggle)
patool 4.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,400 kB
  • sloc: python: 5,517; makefile: 177; sh: 122; vhdl: 1
file content (48 lines) | stat: -rw-r--r-- 1,770 bytes parent folder | download | duplicates (2)
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
# Copyright (C) 2010-2023 Bastian Kleineidam
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Test utility functions"""

import unittest
from patoolib import log, util


class UtilTest(unittest.TestCase):
    """Test class for utility functions"""

    def test_logging(self):
        """Test log.log_*() functions"""
        msg = "this is a test info message 💜"
        log.log_info(msg)
        msg = "this is a test error message 💜"
        log.log_error(msg)
        try:
            raise Exception(msg)
        except Exception:
            log.log_internal_error()

    def test_quote(self):
        """Test util.shell_quote_unix()"""
        self.assertEqual(util.shell_quote_unix("a b"), "'a b'")

    def test_strlist_with_or(self):
        """Test util.strlist()"""
        alist = []
        self.assertEqual(util.strlist_with_or(alist), "")
        alist = ["test1"]
        self.assertEqual(util.strlist_with_or(alist), "test1")
        alist = ["test1", "test2"]
        self.assertEqual(util.strlist_with_or(alist), "test1 or test2")
        alist = ["test1", "test2", "test3"]
        self.assertEqual(util.strlist_with_or(alist), "test1, test2 or test3")