Exemplo n.º 1
0
    def test_wrong_format(self, read_file, filename):
        data = read_file(filename)
        with pytest.raises(SystemInfoError) as ex:
            with patch("builtins.open",
                       mock_open(read_data=data)) as mock_file:
                uptime = Uptime()

        assert str(ex.value) == 'Cannot parse /proc/uptime file'
Exemplo n.º 2
0
    def test_proccesses_number(self, folder, expected):
        dir_path = os.path.dirname(os.path.realpath(__file__))
        ProcessesController._proc_folder = os.path.join(dir_path, folder)
        Process._proc_folder = os.path.join(dir_path, folder)

        uptime = Uptime()
        memory_info = MemInfo()
        processes = ProcessesController(uptime, memory_info.total_memory)
        assert processes.proccesses_number == len(expected)
Exemplo n.º 3
0
    def test_wrong_format(self, pid):
        dir_path = os.path.dirname(os.path.realpath(__file__))
        Process._proc_folder = os.path.join(dir_path, 'test_sysinfo')
        uptime = Uptime()
        Process.set_uptime(uptime)
        memory_info = memory = MemInfo()
        Process.set_memory_info(memory_info.total_memory)

        with pytest.raises(SystemInfoError) as ex:
            process = Process(pid)
Exemplo n.º 4
0
    def get_process(self, request):
        expected, pid = request.param
        dir_path = os.path.dirname(os.path.realpath(__file__))
        Process._proc_folder = os.path.join(dir_path, 'test_sysinfo')

        uptime = Uptime()
        Process.set_uptime(uptime)
        memory_info = memory = MemInfo()
        Process.set_memory_info(memory_info.total_memory)
        process = Process(pid)
        return expected, process
Exemplo n.º 5
0
 def test_load_average_as_string(self, read_file, expected, filename):
     data = read_file(filename)
     with patch("builtins.open", mock_open(read_data=data)) as mock_file:
         uptime = Uptime()
         assert uptime.uptime_as_string == expected
         mock_file.assert_called_with("/proc/uptime")
Exemplo n.º 6
0
 def test_no_file(self):
     with pytest.raises(OSError):
         with patch('builtins.open') as mock_open:
             mock_open.side_effect = OSError
             uptime = Uptime()