File: test_application.py

package info (click to toggle)
pitivi 0.999-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 24,912 kB
  • sloc: python: 23,282; ansic: 2,847; sh: 249; makefile: 21; xml: 19
file content (110 lines) | stat: -rw-r--r-- 4,178 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
# Pitivi video editor
# Copyright (c) 2014, Alex Băluț <alexandru.balut@gmail.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
"""Tests for the application module."""
# pylint: disable=missing-docstring,protected-access,no-self-use
from unittest import mock

from pitivi import application
from pitivi import configure
from tests import common


class TestPitivi(common.TestCase):

    def call_version_info_received(self, version_info):
        app = application.Pitivi()
        giofile = mock.Mock()
        giofile.load_contents_finish.return_value = (True, version_info)
        app._version_info_received_cb(giofile, result=None, user_data=None)
        return app

    def test_version_info(self):
        app = application.Pitivi()
        self.assertTrue(app.isLatest())

        app = self.call_version_info_received("invalid")
        self.assertTrue(app.isLatest())

        app = self.call_version_info_received(
            "%s=CURRENT" % configure.VERSION)
        self.assertTrue(app.isLatest())
        self.assertEqual(configure.VERSION, app.getLatest())

        app = self.call_version_info_received(
            "%s=current\n0=supported" % configure.VERSION)
        self.assertTrue(app.isLatest())
        self.assertEqual(configure.VERSION, app.getLatest())

        app = self.call_version_info_received("999.0=CURRENT")
        self.assertFalse(app.isLatest())
        self.assertEqual("999.0", app.getLatest())

        app = self.call_version_info_received(
            "999.0=CURRENT\n%s=SUPPORTED" % configure.VERSION)
        self.assertFalse(app.isLatest())
        self.assertEqual("999.0", app.getLatest())

        app = self.call_version_info_received("0.91=current")
        self.assertTrue(app.isLatest())
        self.assertEqual("0.91", app.getLatest())

        app = self.call_version_info_received("0.100000000=current")
        self.assertFalse(app.isLatest())
        self.assertEqual("0.100000000", app.getLatest())

    def test_inhibition(self):
        app = application.Pitivi()

        # Check simple_inhibit.
        with mock.patch.object(app, "inhibit") as inhibit_mock:
            inhibit_mock.return_value = 1
            app.simple_inhibit("reason1", "flags1")
            inhibit_mock.return_value = 2
            app.simple_inhibit("reason2", "flags2")
            self.assertEqual(inhibit_mock.call_count, 2)

            inhibit_mock.reset_mock()
            app.simple_inhibit("reason1", "flags1.1")
            self.assertFalse(inhibit_mock.called)

        # Check simple_uninhibit.
        with mock.patch.object(app, "uninhibit") as uninhibit_mock:
            uninhibit_mock.reset_mock()
            app.simple_uninhibit("reason1")
            uninhibit_mock.assert_called_once_with(1)

            uninhibit_mock.reset_mock()
            app.simple_uninhibit("reason1")
            self.assertFalse(uninhibit_mock.called)

            uninhibit_mock.reset_mock()
            app.simple_uninhibit("reason2")
            uninhibit_mock.assert_called_once_with(2)

            uninhibit_mock.reset_mock()
            app.simple_uninhibit("reason2")
            self.assertFalse(uninhibit_mock.called)

            app.simple_uninhibit("reason3")
            self.assertFalse(uninhibit_mock.called)

        # Check again simple_inhibit.
        with mock.patch.object(app, "inhibit") as inhibit_mock:
            app.simple_inhibit("reason1", "flags1")
            self.assertTrue(inhibit_mock.called)