summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2018-07-10 17:14:03 +0200
committerJürg Billeter <j@bitron.ch>2018-07-17 07:56:40 +0200
commit8cd81636a15aa0a6a68640eb8b5ad7268e7c0675 (patch)
tree970378f8fba5353ee7b25a7757cb01ddd112871a
parentba4581f8f7e0c9879cb61237ad5266d286b68d51 (diff)
downloadbuildstream-8cd81636a15aa0a6a68640eb8b5ad7268e7c0675.tar.gz
tests/frontend/push.py: Use ArtifactShare statvfs mocking
This makes it unnecessary to update the free space in the mock object in the middle of tests.
-rw-r--r--tests/frontend/push.py38
1 files changed, 9 insertions, 29 deletions
diff --git a/tests/frontend/push.py b/tests/frontend/push.py
index 8dba3c0a3..e7379807c 100644
--- a/tests/frontend/push.py
+++ b/tests/frontend/push.py
@@ -1,7 +1,5 @@
import os
import pytest
-from collections import namedtuple
-from unittest.mock import MagicMock
from buildstream._exceptions import ErrorDomain
from tests.testutils import cli, create_artifact_share, create_element_size
@@ -211,14 +209,9 @@ def test_artifact_expires(cli, datafiles, tmpdir):
element_path = os.path.join(project, 'elements')
# Create an artifact share (remote artifact cache) in the tmpdir/artifactshare
- with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
-
- # Mock the os.statvfs() call to return a named tuple which emulates an
- # os.statvfs_result object
- statvfs_result = namedtuple('statvfs_result', 'f_blocks f_bfree f_bsize')
- os.statvfs = MagicMock(return_value=statvfs_result(f_blocks=int(10e9),
- f_bfree=(int(12e6) + int(2e9)),
- f_bsize=1))
+ # Mock a file system with 12 MB free disk space
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare'),
+ total_space=int(10e9), free_space=(int(12e6) + int(2e9))) as share:
# Configure bst to push to the cache
cli.configure({
@@ -241,11 +234,6 @@ def test_artifact_expires(cli, datafiles, tmpdir):
assert cli.get_element_state(project, 'element2.bst') == 'cached'
assert_shared(cli, share, project, 'element2.bst')
- # update mocked available disk space now that two 5 MB artifacts have been added
- os.statvfs = MagicMock(return_value=statvfs_result(f_blocks=int(10e9),
- f_bfree=(int(2e6) + int(2e9)),
- f_bsize=1))
-
# Create and build another element of 5 MB (This will exceed the free disk space available)
create_element_size('element3.bst', element_path, [], int(5e6))
result = cli.run(project=project, args=['build', 'element3.bst'])
@@ -269,13 +257,9 @@ def test_artifact_too_large(cli, datafiles, tmpdir):
element_path = os.path.join(project, 'elements')
# Create an artifact share (remote cache) in tmpdir/artifactshare
- with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
-
- # Mock a file system with 5 MB total space
- statvfs_result = namedtuple('statvfs_result', 'f_blocks f_bfree f_bsize')
- os.statvfs = MagicMock(return_value=statvfs_result(f_blocks=int(5e6) + int(2e9),
- f_bfree=(int(5e6) + int(2e9)),
- f_bsize=1))
+ # Mock a file system with 5 MB total space
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare'),
+ total_space=int(5e6) + int(2e9)) as share:
# Configure bst to push to the remote cache
cli.configure({
@@ -312,13 +296,9 @@ def test_recently_pulled_artifact_does_not_expire(cli, datafiles, tmpdir):
element_path = os.path.join(project, 'elements')
# Create an artifact share (remote cache) in tmpdir/artifactshare
- with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
-
- # Mock a file system with 12 MB free disk space
- statvfs_result = namedtuple('statvfs_result', 'f_blocks f_bfree f_bsize')
- os.statvfs = MagicMock(return_value=statvfs_result(f_blocks=int(10e9) + int(2e9),
- f_bfree=(int(12e6) + int(2e9)),
- f_bsize=1))
+ # Mock a file system with 12 MB free disk space
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare'),
+ total_space=int(10e9), free_space=(int(12e6) + int(2e9))) as share:
# Configure bst to push to the cache
cli.configure({