コード例 #1
0
 def test_disk(self):
     metric = DiskUsage()
     self.assertEqual(metric.result(), 0)
     metric.update()
     self.assertGreaterEqual(metric.result(), 0)
     metric.reset()
     self.assertEqual(metric.result(), 0)
コード例 #2
0
    def test_standalone_disk_usage_multi_dir(self):
        with tempfile.TemporaryDirectory() as tmp_dirA:
            with tempfile.TemporaryDirectory() as tmp_dirB:
                uut = DiskUsage([tmp_dirA, tmp_dirB])

                uut.update()
                base_value = uut.result()
                with open(str(Path(tmp_dirA) / 'blob_fileA.bin'), "wb") as f:
                    f.write(os.urandom(512))

                uut.update()
                self.assertLessEqual(base_value, uut.result())

                base_value = uut.result()

                with open(str(Path(tmp_dirB) / 'blob_fileB.bin'), "wb") as f:
                    f.write(os.urandom(512))

                uut.update()
                self.assertLessEqual(base_value, uut.result())
コード例 #3
0
    def test_standalone_disk_usage(self):
        with tempfile.TemporaryDirectory() as tmp_dir:
            uut = DiskUsage(tmp_dir)

            # Assert result is None when created
            self.assertEqual(0, uut.result())

            # Base usage
            uut.update()
            self.assertLessEqual(0, uut.result())

            # Assert reset actually resets
            uut.reset()
            self.assertEqual(0, uut.result())

            uut.update()
            base_value = uut.result()
            with open(str(Path(tmp_dir) / 'blob_file.bin'), "wb") as f:
                f.write(os.urandom(512))

            # Shouldn't change between calls to update
            self.assertEqual(base_value, uut.result())

            uut.update()

            self.assertLessEqual(base_value, uut.result())