Example #1
0
 def setUp(self):
     self.testClass = CheckResources()
     self.toolsSystem = ToolsSystem()
     self.distutils = distutils.util
Example #2
0
class TestCheckResources(unittest.TestCase):
    """ Тестирование класса CheckResources.  """

    testClass = None  # Ссылка на тестируемый класс.
    toolsSystem = None  # Ссылка на класс toolSystem.
    distutils = None  # Ссылка на объект distutils.util


    def setUp(self):
        self.testClass = CheckResources()
        self.toolsSystem = ToolsSystem()
        self.distutils = distutils.util


    def testCheck(self):
        """ Тест класса check() """

        # Проверка типа:
        self.assertRaises(TypeError, self.testClass.check, "ERROR_TYPE", "Non list value")

        # Проверка OS_TYPE:
        self.assertRaises(TypeError, self.testClass.check, "OS_TYPE", "Non list value")
        self.assertRaises(ValueError, self.testClass.check, "OS_TYPE", ["error_value"])
        if sys.platform == "win32":
            self.assertNotEqual(self.testClass.check("OS_TYPE", ["linux"]), None)
            self.assertEqual(self.testClass.check("OS_TYPE", ["linux", "windows"]), None)
            self.assertEqual(self.testClass.check("OS_TYPE", ["windows"]), None)

        # Провека OS_VER:
        if sys.platform == "win32":
            osVer = {  # Идентификаторы и номера версий Windows.
                "5.0": "win2000",
                "5.1": "winxp",
                "5.2": "win2003",
                "6.0": "winvista",
                "6.1": "win7",
                "6.2": "win8",
               }
            curVer = self.toolsSystem.getWindowsVersion()
            self.assertRaises(ValueError, self.testClass.check, "OS_VER", ["error_value"])
            self.assertEqual(self.testClass.check("OS_VER", ["win2000", "win2003", osVer[curVer]]), None)
            if osVer[curVer] != "win2000":
                self.assertNotEqual(self.testClass.check("OS_VER", ["win2000"]), None)
            else:
                self.assertNotEqual(self.testClass.check("OS_VER", ["win2008"]), None)
            self.assertNotEqual(self.testClass.check("OS_VER", []), None)

        # Проверка OS_ARCH:
        if sys.platform == "win32":
            curArch = "x64" if self.distutils.get_platform().find("64") else "x32"  # Текущая архитектура комьпютера.
            self.assertNotEqual(self.testClass.check("OS_ARCH", []), None)
            self.assertRaises(ValueError, self.testClass.check, "OS_ARCH", ["error_value"])
            self.assertEqual(self.testClass.check("OS_ARCH", [curArch]), None)
            if curArch == "x64":
                self.assertNotEqual(self.testClass.check("OS_ARCH", ["x32"]), None)
            else:
                self.assertNotEqual(self.testClass.check("OS_ARCH", ["x64"]), None)

        # Прверка FILE_EXIST:
        self.assertRaises(ValueError, self.testClass.check, "FILE_EXIST", [])
        if os.path.exists("c:\\Windows\\explorer.exe"):
            self.assertEqual(self.testClass.check("FILE_EXIST", ["c:\\Windows\\explorer.exe"]), None)
            self.assertEqual(self.testClass.check("FILE_EXIST", ["c:\\Windows\\explorer.exe", "c:\\Windows\\explorer.exe"]), None)
            self.assertNotEqual(self.testClass.check("FILE_EXIST", ["c:\\Windows\\explorer.exe", "c:\\Windows\\NonFileExist.exe"]), None)
            self.assertRaises(ValueError, self.testClass.check, "FILE_EXIST", ["c:\\Windows\\explorer.exe", ""])
        self.assertNotEqual(self.testClass.check("FILE_EXIST", ["c:\\Windows\\NonFileExist.exe"]), None)