forked from tableau/server-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_utils.py
More file actions
37 lines (25 loc) · 789 Bytes
/
_utils.py
File metadata and controls
37 lines (25 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os.path
import unittest
from contextlib import contextmanager
TEST_ASSET_DIR = os.path.join(os.path.dirname(__file__), "assets")
def asset(filename):
return os.path.join(TEST_ASSET_DIR, filename)
def read_xml_asset(filename):
with open(asset(filename), "rb") as f:
return f.read().decode("utf-8")
def read_xml_assets(*args):
return map(read_xml_asset, args)
@contextmanager
def mocked_time():
mock_time = 0
def sleep_mock(interval):
nonlocal mock_time
mock_time += interval
def get_time():
return mock_time
try:
patch = unittest.mock.patch
except AttributeError:
from unittest.mock import patch
with patch("time.sleep", sleep_mock), patch("time.time", get_time):
yield get_time