FreeCAD

Форк
0
/
test_workers_utility.py 
78 строк · 3.7 Кб
1
# SPDX-License-Identifier: LGPL-2.1-or-later
2
# ***************************************************************************
3
# *                                                                         *
4
# *   Copyright (c) 2022-2023 FreeCAD Project Association                   *
5
# *                                                                         *
6
# *   This file is part of FreeCAD.                                         *
7
# *                                                                         *
8
# *   FreeCAD is free software: you can redistribute it and/or modify it    *
9
# *   under the terms of the GNU Lesser General Public License as           *
10
# *   published by the Free Software Foundation, either version 2.1 of the  *
11
# *   License, or (at your option) any later version.                       *
12
# *                                                                         *
13
# *   FreeCAD is distributed in the hope that it will be useful, but        *
14
# *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
15
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
16
# *   Lesser General Public License for more details.                       *
17
# *                                                                         *
18
# *   You should have received a copy of the GNU Lesser General Public      *
19
# *   License along with FreeCAD. If not, see                               *
20
# *   <https://www.gnu.org/licenses/>.                                      *
21
# *                                                                         *
22
# ***************************************************************************
23

24
import unittest
25
import os
26
import FreeCAD
27
from addonmanager_workers_utility import ConnectionChecker
28
from PySide import QtCore
29

30
import NetworkManager
31

32

33
class TestWorkersUtility(unittest.TestCase):
34

35
    MODULE = "test_workers_utility"  # file name without extension
36

37
    @unittest.skip("Test is slow and uses the network: refactor!")
38
    def setUp(self):
39
        self.test_dir = os.path.join(
40
            FreeCAD.getHomePath(), "Mod", "AddonManager", "AddonManagerTest", "data"
41
        )
42
        self.last_result = None
43

44
        url = "https://api.github.com/zen"
45
        NetworkManager.InitializeNetworkManager()
46
        result = NetworkManager.AM_NETWORK_MANAGER.blocking_get(url)
47
        if result is None:
48
            self.skipTest("No active internet connection detected")
49

50
    def test_connection_checker_basic(self):
51
        """Tests the connection checking worker's basic operation: does not exit until worker thread completes"""
52
        worker = ConnectionChecker()
53
        worker.success.connect(self.connection_succeeded)
54
        worker.failure.connect(self.connection_failed)
55
        self.last_result = None
56
        worker.start()
57
        while worker.isRunning():
58
            QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 50)
59
        QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
60
        self.assertEqual(self.last_result, "SUCCESS")
61

62
    def test_connection_checker_thread_interrupt(self):
63
        worker = ConnectionChecker()
64
        worker.success.connect(self.connection_succeeded)
65
        worker.failure.connect(self.connection_failed)
66
        self.last_result = None
67
        worker.start()
68
        worker.requestInterruption()
69
        while worker.isRunning():
70
            QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents, 50)
71
        QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
72
        self.assertIsNone(self.last_result, "Requesting interruption of thread failed to interrupt")
73

74
    def connection_succeeded(self):
75
        self.last_result = "SUCCESS"
76

77
    def connection_failed(self):
78
        self.last_result = "FAILURE"
79

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.