[Notes] [Git][BuildStream/buildstream][BenjaminSchubert/fix-quota-tests] fixup! Mock storage space checks for tests.



Title: GitLab

Benjamin Schubert pushed to branch BenjaminSchubert/fix-quota-tests at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • tests/testutils/mock_os.py deleted
    1
    -from contextlib import contextmanager
    
    2
    -import os
    
    3
    -
    
    4
    -
    
    5
    -# MockAttributeResult
    
    6
    -#
    
    7
    -# A class to take a dictionary of kwargs and make them accessible via
    
    8
    -# attributes of the object.
    
    9
    -#
    
    10
    -class MockAttributeResult(dict):
    
    11
    -    __getattr__ = dict.get
    
    12
    -
    
    13
    -
    
    14
    -# mock_statvfs():
    
    15
    -#
    
    16
    -# Gets a function which mocks statvfs and returns a statvfs result with the kwargs accessible.
    
    17
    -#
    
    18
    -# Returns:
    
    19
    -#    func(path) -> object: object will have all the kwargs accessible via object.kwarg
    
    20
    -#
    
    21
    -# Example:
    
    22
    -#    statvfs = mock_statvfs(f_blocks=10)
    
    23
    -#    result = statvfs("regardless/of/path")
    
    24
    -#    assert result.f_blocks == 10 # True
    
    25
    -def mock_statvfs(**kwargs):
    
    26
    -    def statvfs(path):
    
    27
    -        return MockAttributeResult(kwargs)
    
    28
    -    return statvfs
    
    29
    -
    
    30
    -
    
    31
    -# monkey_patch()
    
    32
    -#
    
    33
    -# with monkey_patch("statvfs", custom_statvfs):
    
    34
    -#    assert os.statvfs == custom_statvfs # True
    
    35
    -# assert os.statvfs == custom_statvfs # False
    
    36
    -#
    
    37
    -@contextmanager
    
    38
    -def monkey_patch(to_patch, patched_func):
    
    39
    -    orig = getattr(os, to_patch)
    
    40
    -    setattr(os, to_patch, patched_func)
    
    41
    -    try:
    
    42
    -        yield
    
    43
    -    finally:
    
    44
    -        setattr(os, to_patch, orig)

  • tests/utils/misc.py
    1 1
     from buildstream import _yaml
    
    2
    -from ..testutils import mock_os
    
    3 2
     from ..testutils.runcli import cli
    
    4 3
     
    
    5 4
     import os
    
    ... ... @@ -23,9 +22,13 @@ def test_parse_size_over_1024T(cli, tmpdir):
    23 22
         os.makedirs(str(project))
    
    24 23
         _yaml.dump({'name': 'main'}, str(project.join("project.conf")))
    
    25 24
     
    
    26
    -    bavail = (1025 * TiB) / BLOCK_SIZE
    
    27
    -    patched_statvfs = mock_os.mock_statvfs(f_bavail=bavail, f_bsize=BLOCK_SIZE)
    
    28
    -    with mock_os.monkey_patch("statvfs", patched_statvfs):
    
    25
    +    volume_space_patch = mock.patch(
    
    26
    +        "buildstream._artifactcache.artifactcache.ArtifactCache._get_volume_space_info_for",
    
    27
    +        autospec=True,
    
    28
    +        return_value=(1025 * TiB, 1025 * TiB)
    
    29
    +    )
    
    30
    +
    
    31
    +    with volume_space_patch:
    
    29 32
             result = cli.run(project, args=["build", "file.bst"])
    
    30 33
             failure_msg = 'Your system does not have enough available space to support the cache quota specified.'
    
    31 34
             assert failure_msg in result.stderr



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]