コード例 #1
0
ファイル: test_hardware.py プロジェクト: PeterM358/python_OOP
 def test_uninstall__when_invalid_software__expect_NONE(self):
     software = ExpressSoftware('Linux', 200, 200)
     software2 = ExpressSoftware('Linux', 1, 1)
     self.hardware.install(software)
     self.assertEqual(1, len(self.hardware.software_components))
     self.assertIsNone(self.hardware.uninstall(software2))
     self.assertEqual(1, len(self.hardware.software_components))
コード例 #2
0
 def setUp(self) -> None:
     self.hw = Hardware("Test", "Power", 100, 100)
     self.hw2 = Hardware("Test2", "Hevy", 200, 200)
     self.sw = ExpressSoftware("Sw", 10, 10)
     self.sw2 = ExpressSoftware("Sw1", 1, 1000)
     self.sw3 = ExpressSoftware("Sw2", 100000, 1)
     self.sw4 = ExpressSoftware("Sw3", 1000000, 1000000)
コード例 #3
0
 def test_express_components_length(self):
     count = 0
     ex = ExpressSoftware("express1", 1, 10)
     ex2 = ExpressSoftware("express2", 2, 20)
     self.hardware.install(ex)
     self.hardware.install(ex2)
     for s in self.hardware.software_components:
         if s.type == "Express":
             count += 1
     self.assertEqual(count, len(self.hardware.software_components))
コード例 #4
0
 def test_uninstall__when_software_in_components__expect_to_uninstall_it(
         self):
     software = ExpressSoftware('Express', 200, 100)
     self.hardware.install(software)
     self.assertEqual(1, len(self.hardware.software_components))
     self.hardware.uninstall(software)
     self.assertEqual([], self.hardware.software_components)
コード例 #5
0
ファイル: test_hardware.py プロジェクト: borislav777/SoftUni
    def test_install_dont_have_memory_and_capacity(self):
        software = ExpressSoftware("Nero", 150, 250)
        with self.assertRaises(Exception) as ex:
            self.hardware.install(software)

        self.assertEqual("Software cannot be installed", str(ex.exception))
        self.assertEqual([], self.hardware.software_components)
コード例 #6
0
 def test_uninstall(self):
     hw = Hardware('name', 'type', 1000, 512)
     sw = ExpressSoftware('test', 100, 100)
     hw.install(sw)
     self.assertEqual(1, len(hw.software_components))
     hw.uninstall(sw)
     self.assertEqual(0, len(hw.software_components))
コード例 #7
0
 def test_install_raises(self):
     with self.assertRaises(Exception) as ex:
         software = ExpressSoftware('test',
                                    capacity_consumption=10000,
                                    memory_consumption=10000)
         self.hardware.install(software)
     self.assertEqual("Software cannot be installed", str(ex.exception))
コード例 #8
0
 def test_uninstall(self):
     software = ExpressSoftware('test',
                                capacity_consumption=100,
                                memory_consumption=100)
     self.hardware.install(software)
     self.assertListEqual([software], self.hardware.software_components)
     self.hardware.uninstall(software)
     self.assertListEqual([], self.hardware.software_components)
コード例 #9
0
    def test_install__when_not_enough_memory_and_capacity__expect_exception(
            self):
        software = ExpressSoftware('Test ex software', 350, 500)

        with self.assertRaises(Exception) as ex:
            self.hardware.install(software)

        self.assertEqual("Software cannot be installed", str(ex.exception))
コード例 #10
0
 def register_express_software(hardware_name: str, name: str,
                               capacity_consumption: int,
                               memory_consumption: int):
     software = ExpressSoftware(name, capacity_consumption,
                                memory_consumption)
     hardware = System.find_hardware(hardware_name)
     if hardware is None:
         return 'Hardware does not exist'
     return System.register_software(hardware, software)
コード例 #11
0
 def register_express_software(hardware_name: str, name: str, capacity_consumption: int, memory_consumption: int):
     if hardware_name not in [each.name for each in System._hardware]:
         return "Hardware does not exist"
     es = ExpressSoftware(name, capacity_consumption, memory_consumption)
     on_hw_to_install = [each for each in System._hardware if each.name == hardware_name][0]
     result = on_hw_to_install.install(es)
     if result == "Software cannot be installed":
         return "Software cannot be installed"
     System._software.append(es)
コード例 #12
0
    def test_uninstall__when_software_not_exist__expect_to_remove_it_from_the_list(
            self):
        software_l = LightSoftware('Test software', 5, 2)
        self.hardware.install(software_l)
        self.assertEqual(1, len(self.hardware.software_components))

        software_ex = ExpressSoftware('Test ex software', 350, 500)
        self.hardware.uninstall(software_ex)
        self.assertEqual(1, len(self.hardware.software_components))
コード例 #13
0
ファイル: test_hardware.py プロジェクト: borko81/SU_OOP_2021
    def test_install_when_is_ok_heavy(self):
        s = LightSoftware('Light', 10, 10)
        p = ExpressSoftware('Express', 10, 10)

        self.hardware.install(s)
        self.assertEqual(self.hardware.software_components[0], s)

        self.power.install(p)
        self.assertEqual(self.power.software_components[0], p)
コード例 #14
0
    def register_express_software(hardware_name: str, name: str,
                                  capacity_consumption: int,
                                  memory_consumption: int):
        hardware_found = False
        for hardware in System._hardware:
            if hardware.name == hardware_name:
                hardware_found = True
                try:
                    hardware.install(
                        ExpressSoftware(name, capacity_consumption,
                                        memory_consumption))
                except Exception:
                    return "Software cannot be installed"
                System._software.append(
                    ExpressSoftware(name, capacity_consumption,
                                    memory_consumption))

        if not hardware_found:
            return "Hardware does not exist"
コード例 #15
0
 def register_express_software(hardware_name: str, name: str, capacity_consumption: int, memory_consumption: int):
     hardware = System.find_hardware_by_name(hardware_name)
     if not hardware:
         return "Hardware does not exist"
     es = ExpressSoftware(name, capacity_consumption, memory_consumption)
     try:
         hardware.install(es)
         System._software.append(es)
     except Exception:
         return "Software cannot be installed"
コード例 #16
0
 def register_express_software(hardware_name: str, name: str, capacity_consumption: int, memory_consumption: int):
     try:
         hardware = [h for h in System._hardware if h.name == hardware_name][0]
         software = ExpressSoftware(name, capacity_consumption, memory_consumption)
         hardware.install(software)
         System._software.append(software)
     except IndexError:
         return "Hardware does not exist"
     except Exception as ex:
         return str(ex)
コード例 #17
0
ファイル: system.py プロジェクト: mariatmv/PythonOOP
 def register_express_software(hardware_name: str, name:str, capacity_consumption:int, memory_consumption:int):
     hardware = [x for x in System._hardware if x.name == hardware_name]
     if not hardware:
         return "Hardware does not exist"
     try:
         s = ExpressSoftware(name, capacity_consumption, memory_consumption)
         hardware[0].install(s)
         System._software.append(s)
     except Exception as exc:
         return str(exc)
コード例 #18
0
 def register_express_software(hardware_name, name, capacity_consumption, memory_consumption):
     for hw in System._hardware:
         if hw.name == hardware_name:
             express_software = ExpressSoftware(name, capacity_consumption, memory_consumption)
             try:
                 hw.install(express_software)
                 System._software.append(express_software)
             except Exception as ex:
                 return str(ex)
     
     return 'Hardware does not exist'
コード例 #19
0
ファイル: test_hardware.py プロジェクト: borko81/SU_OOP_2021
    def test_install_when_not_good_param_heavy(self):
        s = LightSoftware('Light', 200, 384)
        p = ExpressSoftware('Express', 10, 900)

        with self.assertRaises(Exception) as ex:
            self.hardware.install(s)
        self.assertEqual(str(ex.exception), "Software cannot be installed")

        with self.assertRaises(Exception) as ex:
            self.power.install(p)
        self.assertEqual(str(ex.exception), "Software cannot be installed")
コード例 #20
0
    def register_express_software(hardware_name: str, name: str, capacity_consumption: int, memory_consumption: int):
        if hardware_name not in map(lambda x: x.name, System._hardware):
            return "Hardware does not exist"
        hardware = [h for h in System._hardware if h.name == hardware_name][0]
        software = ExpressSoftware(name, capacity_consumption, memory_consumption)
        try:
            hardware.install(software)

        except Exception as ex:
            return str(ex)
        System._software.append(software)
コード例 #21
0
ファイル: system.py プロジェクト: miroslav-kostov/exam_prep_1
 def register_express_software(hardware_name: str, name: str, capacity_consumption: int, memory_consumption: int):
     hardware = [hardware for hardware in System._hardware if hardware.name == hardware_name]
     software = ExpressSoftware(name, capacity_consumption, memory_consumption)
     if not hardware:
         return "Hardware does not exist"
     try:
         hardware = hardware[0]
         hardware.install(software)
         System._software.append(software)
     except Exception as ex:
         return str(ex)
コード例 #22
0
    def register_express_software(hardware_name: str, name: str, capacity_consumption: int, memory_consumption: int):
        try:
            hardware = [x for x in System._hardware if x.name == hardware_name][0]
        except IndexError:
            return "Hardware does not exist"

        express_software = ExpressSoftware(name, capacity_consumption, memory_consumption)
        try:
            hardware.install(express_software)
            System._software.append(express_software)
        except Exception:
            return Exception("Software cannot be installed")
コード例 #23
0
    def register_express_software(hardware_name, name, capacity_consumption, memory_consumption):
        software = ExpressSoftware(name, capacity_consumption, memory_consumption)
        try:
            hardware = [h for h in System._hardware if h.name == hardware_name][0]
        except IndexError:
            return "Hardware does not exist"

        try:
            hardware.install(software)
            System._software.append(software)
        except Exception:
            return "Software cannot be installed"
コード例 #24
0
ファイル: system.py プロジェクト: Tarantulata/Portfolio
    def register_express_software(hardware_name, name, capacity_consumption, memory_consumption):
        hardware = System._hardware_by_name(hardware_name)
        if hardware is None:
            return "Hardware does not exist"

        software = ExpressSoftware(name, capacity_consumption, memory_consumption)
        try:
            hardware.install(software)
        except Exception:
            return "Software cannot be installed"

        System._software.append(software)
コード例 #25
0
ファイル: system.py プロジェクト: MiroVatov/Python-SoftUni
    def register_express_software(hardware_name: str, name: str, capacity_consumption: int, memory_consumption: int):
        hardware = [hard for hard in System._hardware if hard.name == hardware_name]
        if not hardware:
            return f"Hardware does not exist"
        hardware = hardware[0]
        express_software = ExpressSoftware(name, capacity_consumption, memory_consumption)

        try:
            hardware.install(express_software)
            System._software.append(express_software)
        except Exception as exception:
            return exception.args[0]
コード例 #26
0
 def test_custom_repr(self):
     ls = LightSoftware("light1", 1, 10)
     ex = ExpressSoftware("express1", 1, 10)
     self.hardware.install(ls)
     self.hardware.install(ex)
     self.assertEqual(
         repr(self.hardware), "Hardware Component - test\n"
         "Express Software Components: 1\n"
         "Light Software Components: 1\n"
         "Memory Usage: 25 / 100\n"
         "Capacity Usage: 2 / 10\n"
         "Type: test_type\n"
         "Software Components: light1, express1")
コード例 #27
0
 def register_express_software(hardware_name: str, name: str,
                               capacity_consumption: int,
                               memory_consumption: int):
     hardware = System.exist_hardware(hardware_name)
     if not hardware:
         return 'Hardware does not exist'
     software = ExpressSoftware(name, capacity_consumption,
                                memory_consumption)
     try:
         hardware.install(software)
     except Exception:
         return 'Software cannot be installed'
     System._software.append(software)
コード例 #28
0
 def register_express_software(hardware_name: str, name: str, capacity_consumption: int, memory_consumption: int):
     # •	If the hardware with the given name does NOT exist, return a message "Hardware does not exist"
     # •	Otherwise, create an ExpressSoftware instance, install it on the hardware (if possible) and add it to the software list (if installed successfully)
     # •	If the installation is not possible return the message of the raised Exception
     try:
         hardware = [h for h in System._hardware if h.name == hardware_name][0]
         software = ExpressSoftware(name, capacity_consumption, memory_consumption)
         hardware.install(software)
         System._software.append(software)
     except IndexError:
         return "Hardware does not exist"
     except Exception as ex:
         return str(ex)
コード例 #29
0
ファイル: system.py プロジェクト: AntoniyaV/SoftUni-Exercises
    def register_express_software(hw_name: str, name: str, capacity_consumption: int, memory_consumption: int):
        hardware_match = System.return_component_match(hw_name, System._hardware)
        if not hardware_match:
            return "Hardware does not exist"

        hardware = hardware_match[0]
        express_sw = ExpressSoftware(name, capacity_consumption, memory_consumption)

        try:
            hardware.install(express_sw)
            System._software.append(express_sw)
        except Exception as ex:
            return str(ex)
コード例 #30
0
 def register_express_software(hardware_name: str, name: str,
                               capacity_consumption: int,
                               memory_consumption: int):
     hardware = System.get_hardware_by_name(hardware_name)
     if not hardware:
         return "Hardware does not exist"
     software = ExpressSoftware(name, capacity_consumption,
                                memory_consumption)
     try:
         hardware.install(software)  # TODO CHECK IF RAISE IS AUTOMATIC
     except ValueError:
         return "Software cannot be installed"
     System._software.append(software)