File: test_log.py

package info (click to toggle)
duplicity 3.0.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,620 kB
  • sloc: python: 25,580; sh: 976; ansic: 392; makefile: 83
file content (77 lines) | stat: -rw-r--r-- 2,394 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4; encoding:utf-8 -*-
#
# Copyright 2008 Michael Terry
#
# This file is part of duplicity.
#
# Duplicity 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 2 of the License, or (at your
# option) any later version.
#
# Duplicity 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 duplicity; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


import os
import sys
import unittest

from testing import _runtest_dir
from testing import _top_dir
from . import FunctionalTestCase


class LogTest(FunctionalTestCase):
    """Test machine-readable functions/classes in log.py"""

    logfile = f"{_runtest_dir}/duplicity.log"

    def setUp(self):
        super().setUp()
        assert not os.system(f"rm -f {self.logfile}")

    def tearDown(self):
        assert not os.system(f"rm -f {self.logfile}")
        super().tearDown()

    def test_command_line_error(self):
        """Check notification of a simple error code"""

        # Run actual duplicity command (will fail because bad dirs passed)
        basepython = f"python{sys.version_info.major}.{sys.version_info.minor}"
        cmd = (
            f"{basepython} {_top_dir}/duplicity/__main__.py --log-file={self.logfile} "
            f"full testing baddir >/dev/null 2>&1"
        )
        os.system(cmd)

        # The format of the file should be:
        # """ERROR 23 CommandLineError
        # . Blah blah blah.
        # . Blah blah blah.
        #
        # """
        f = open(self.logfile, "r")
        linecount = 0
        lastline = False
        for line in f:
            assert not lastline
            linecount += 1
            if linecount == 1:
                assert line == "ERROR 23 CommandLineError\n"
            elif line[0] != "\n":
                assert line.startswith(r". ")
            else:
                lastline = True
        assert lastline, f"{line=}"


if __name__ == "__main__":
    unittest.main()