summaryrefslogtreecommitdiff
path: root/tests/testutils
diff options
context:
space:
mode:
authorBenjamin Schubert <bschubert15@bloomberg.net>2018-08-10 18:10:13 +0100
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2018-12-13 10:24:11 +0000
commitd03bf31619f739cb85ece06eb3e94a314441e097 (patch)
treed3c075924a0b20a2e1e2c1c75f4caac7f4cf19f5 /tests/testutils
parentb65284410329b7f55a0d097b88d297480f9f7307 (diff)
downloadbuildstream-d03bf31619f739cb85ece06eb3e94a314441e097.tar.gz
Mock storage space checks for tests.BenjaminSchubert/fix-quota-tests
Fix #530 - Extract free space computation in a function for easier mocking - Mock space computation during cache quota tests - Mock cache size during cachque quota tests - Add two more tests when the configuration would require to much storage space
Diffstat (limited to 'tests/testutils')
-rw-r--r--tests/testutils/mock_os.py44
1 files changed, 0 insertions, 44 deletions
diff --git a/tests/testutils/mock_os.py b/tests/testutils/mock_os.py
deleted file mode 100644
index 109593b16..000000000
--- a/tests/testutils/mock_os.py
+++ /dev/null
@@ -1,44 +0,0 @@
-from contextlib import contextmanager
-import os
-
-
-# MockAttributeResult
-#
-# A class to take a dictionary of kwargs and make them accessible via
-# attributes of the object.
-#
-class MockAttributeResult(dict):
- __getattr__ = dict.get
-
-
-# mock_statvfs():
-#
-# Gets a function which mocks statvfs and returns a statvfs result with the kwargs accessible.
-#
-# Returns:
-# func(path) -> object: object will have all the kwargs accessible via object.kwarg
-#
-# Example:
-# statvfs = mock_statvfs(f_blocks=10)
-# result = statvfs("regardless/of/path")
-# assert result.f_blocks == 10 # True
-def mock_statvfs(**kwargs):
- def statvfs(path):
- return MockAttributeResult(kwargs)
- return statvfs
-
-
-# monkey_patch()
-#
-# with monkey_patch("statvfs", custom_statvfs):
-# assert os.statvfs == custom_statvfs # True
-# assert os.statvfs == custom_statvfs # False
-#
-@contextmanager
-def monkey_patch(to_patch, patched_func):
- orig = getattr(os, to_patch)
- setattr(os, to_patch, patched_func)
- try:
- yield
- finally:
- setattr(os, to_patch, orig)