Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2041ffd

Browse filesBrowse files
author
Jon Wayne Parrott
committed
Merge pull request GoogleCloudPlatform#190 from GoogleCloudPlatform/pytest-storage
Moving storage samples to py.test
2 parents d0e18c2 + fa3383b commit 2041ffd
Copy full SHA for 2041ffd

File tree

Expand file treeCollapse file tree

4 files changed

+43
-26
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+43
-26
lines changed

‎conftest.py

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
import pytest
4+
from testing.cloud import Config, get_resource_path
5+
6+
7+
@pytest.fixture(scope='session')
8+
def cloud_config():
9+
"""Provides a configuration option as a proxy to environment variables."""
10+
return Config()
11+
12+
13+
@pytest.fixture(scope='module')
14+
def resource(request):
15+
"""Provides a function that returns the full path to a local or global
16+
testing resource"""
17+
local_path = os.path.dirname(request.module.__file__)
18+
return lambda *args: get_resource_path(args, local_path)

‎storage/api/compose_objects_test.py

Copy file name to clipboardExpand all lines: storage/api/compose_objects_test.py
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
# limitations under the License.
1313

1414
from compose_objects import main
15-
from testing import CloudTest
1615

1716

18-
class TestComposeObjects(CloudTest):
19-
def test_main(self):
20-
main(
21-
self.config.CLOUD_STORAGE_BUCKET,
22-
'dest.txt',
23-
[self.resource_path('file1.txt'),
24-
self.resource_path('file2.txt')]
25-
)
17+
def test_main(cloud_config, resource):
18+
main(
19+
cloud_config.CLOUD_STORAGE_BUCKET,
20+
'dest.txt',
21+
[resource('file1.txt'),
22+
resource('file2.txt')]
23+
)

‎storage/api/list_objects_test.py

Copy file name to clipboardExpand all lines: storage/api/list_objects_test.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
# limitations under the License.
1313

1414
from list_objects import main
15-
from testing import CloudTest
1615

1716

18-
class TestListObjects(CloudTest):
19-
def test_main(self):
20-
main(self.config.CLOUD_STORAGE_BUCKET)
17+
def test_main(cloud_config):
18+
main(cloud_config.CLOUD_STORAGE_BUCKET)

‎testing/cloud.py

Copy file name to clipboardExpand all lines: testing/cloud.py
+16-13Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ def __getattr__(self, name):
4747
return os.environ[name]
4848

4949

50+
def get_resource_path(resource, local_path):
51+
global_resource_path = os.path.join(GLOBAL_RESOURCE_PATH, *resource)
52+
local_resource_path = os.path.join(local_path, 'resources', *resource)
53+
54+
if os.path.exists(local_resource_path):
55+
return local_resource_path
56+
57+
if os.path.exists(global_resource_path):
58+
return global_resource_path
59+
60+
raise EnvironmentError('Resource {} not found.'.format(
61+
os.path.join(*resource)))
62+
63+
5064
class CloudTest(unittest.TestCase):
5165
"""Common base class for cloud tests."""
5266
def __init__(self, *args, **kwargs):
@@ -58,16 +72,5 @@ def setUpClass(self):
5872
silence_requests()
5973

6074
def resource_path(self, *resource):
61-
global_resource_path = os.path.join(GLOBAL_RESOURCE_PATH, *resource)
62-
local_resource_path = os.path.join(
63-
os.path.dirname(inspect.getfile(self.__class__)),
64-
'resources', *resource)
65-
66-
if os.path.exists(local_resource_path):
67-
return local_resource_path
68-
69-
if os.path.exists(global_resource_path):
70-
return global_resource_path
71-
72-
raise EnvironmentError('Resource {} not found.'.format(
73-
os.path.join(*resource)))
75+
local_path = os.path.dirname(inspect.getfile(self.__class__))
76+
return get_resource_path(resource, local_path)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.