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
|
# SPDX-FileCopyrightText: © 2025 Christian Buhtz <c.buhtz@posteo.jp>
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This file is part of the program "Back In Time" which is released under GNU
# General Public License v2 (GPLv2). See LICENSES directory or go to
# <https://spdx.org/licenses/GPL-2.0-or-later.html>.
"""Tests about statefile module."""
# pylint: disable=wrong-import-position,wrong-import-order
import unittest
from qttools_path import register_backintime_path
register_backintime_path('common')
import statedata # noqa: E402
class IsSingleton(unittest.TestCase):
"""StateData instance is a singleton."""
@classmethod
def tearDownClass(cls):
# Delete existing StateData instance
try:
# pylint: disable-next=protected-access
del statedata.StateData._instances[statedata.StateData]
except KeyError:
pass
def setUp(self):
# Clean up all instances
try:
# pylint: disable-next=protected-access
del statedata.StateData._instances[statedata.StateData]
except KeyError:
pass
def test_identity(self):
"""Identical identity."""
one = statedata.StateData()
two = statedata.StateData()
self.assertEqual(id(one), id(two))
def test_content(self):
"""Identical values."""
one = statedata.StateData()
two = statedata.StateData()
one['foobar'] = 7
self.assertEqual(one, two)
class Properties(unittest.TestCase):
"""Property access without errors."""
@classmethod
def tearDownClass(cls):
# Delete existing StateData instance
try:
# pylint: disable-next=protected-access
del statedata.StateData._instances[statedata.StateData]
except KeyError:
pass
def setUp(self):
# Delete existing StateData instance
try:
# pylint: disable-next=protected-access
del statedata.StateData._instances[statedata.StateData]
except KeyError:
pass
def test_read_empty_global(self):
"""Read properties from empty state data"""
sut = statedata.StateData()
self.assertEqual(sut.msg_release_candidate, None)
self.assertEqual(sut.msg_encfs_global, False)
self.assertEqual(sut.mainwindow_show_hidden, False)
self.assertEqual(sut.files_view_sorting, (0, 0))
self.assertEqual(sut.mainwindow_main_splitter_widths, (150, 450))
self.assertEqual(sut.mainwindow_second_splitter_widths, (150, 300))
with self.assertRaises(KeyError):
# pylint: disable=pointless-statement
sut.mainwindow_coords
sut.mainwindow_dims
sut.logview_dims
sut.files_view_col_widths
def test_profile_not_exist(self):
"""Profile does not exists."""
sut = statedata.StateData()
profile = sut.profile(42)
with self.assertRaises(KeyError):
# pylint: disable=pointless-statement
profile.last_path
|