Skip to content

Commit ada70ff

Browse files
authoredJul 5, 2024
Merge branch 'master' into FSTORE-1463
2 parents 1892354 + b208343 commit ada70ff

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
 

‎python/tests/client/test_base_client.py

+4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import requests
2121
from hsfs.client.base import Client
2222
from hsfs.client.exceptions import RestAPIError
23+
from tests.util import changes_environ
2324

2425

2526
class TestBaseClient:
27+
@changes_environ
2628
def test_valid_token_no_retires(self, mocker):
2729
# Arrange
2830
os.environ[Client.REST_ENDPOINT] = "True"
@@ -48,6 +50,7 @@ def test_valid_token_no_retires(self, mocker):
4850
# Assert
4951
assert spy_retry_token_expired.call_count == 0
5052

53+
@changes_environ
5154
def test_invalid_token_retires(self, mocker):
5255
# Arrange
5356
os.environ[Client.REST_ENDPOINT] = "True"
@@ -77,6 +80,7 @@ def test_invalid_token_retires(self, mocker):
7780
# Assert
7881
assert spy_retry_token_expired.call_count == 10
7982

83+
@changes_environ
8084
def test_invalid_token_retires_backoff_break(self, mocker):
8185
# Arrange
8286
os.environ[Client.REST_ENDPOINT] = "True"

‎python/tests/util.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright 2024 Hopsworks AB
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
import os
18+
from functools import wraps
19+
20+
21+
def changes_environ(f):
22+
@wraps(f)
23+
def g(*args, **kwds):
24+
old_environ = os.environ.copy()
25+
try:
26+
return f(*args, **kwds)
27+
finally:
28+
os.environ.clear()
29+
os.environ.update(old_environ)
30+
31+
return g

0 commit comments

Comments
 (0)