Skip to content

Commit 4d45a5c

Browse files
committed
Removing pyfakefs and using tempdirs
1 parent 601c660 commit 4d45a5c

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ def read(fname):
5656
"six",
5757
"colorama>=0.3,<0.4",
5858
],
59-
tests_require=["mock>=2", "pytest>=3", "pyfakefs==3.5.3"],
59+
tests_require=["mock>=2", "pytest>=3"],
6060
extras_require={"colorized_logs": ["colorlog"]},
6161
)

test/test/host_test_black_box.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
import re
2020

2121
import threading
22+
import shutil
23+
import tempfile
2224
from builtins import super
2325
from copy import copy
2426
from mbed_os_tools.test import init_host_test_cli_params
2527
from mbed_os_tools.test.host_tests_runner.host_test_default import DefaultTestSelector
2628
from mock import patch, MagicMock
27-
from pyfakefs import fake_filesystem_unittest
2829

2930

3031
class MockThread(threading.Thread):
3132
def __init__(self, target=None, args=None):
3233
super().__init__(target=target, args=args)
33-
print('Mock Thread constr')
3434
self._terminates = 0
3535
self.exitcode = 0 # TODO maybe this needs to be setable? Mock sys.exit
3636

@@ -44,8 +44,8 @@ def __init__(self, *args, **kwargs):
4444
self._kwargs = kwargs
4545
self._open = True
4646
self._rx_counter = 0
47-
self._tx_buffer = ""
48-
self._rx_buffer = ""
47+
self._tx_buffer = b""
48+
self._rx_buffer = b""
4949
self._upstream_write_cb = None
5050

5151
def read(self, count):
@@ -63,12 +63,15 @@ def close(self):
6363
self._open = False
6464

6565
def downstream_write(self, data):
66+
self._rx_buffer += data.encode("utf-8")
67+
68+
def downstream_write_bytes(self, data):
6669
self._rx_buffer += data
6770

6871
def on_upstream_write(self, func):
6972
self._upstream_write_cb = func
7073

71-
kv_regex = re.compile(r"\{\{([\w\d_-]+);([^\}]+)\}\}")
74+
kv_regex = re.compile("\{\{([\w\d_-]+);([^\}]+)\}\}")
7275

7376
class MockMbedDevice(object):
7477
def __init__(self, serial):
@@ -90,7 +93,7 @@ def send_kv(self, key, value):
9093
self._serial.downstream_write("{{{{{};{}}}}}\r\n".format(key, value))
9194

9295
def on_write(self, data):
93-
kvs = kv_regex.findall(data)
96+
kvs = kv_regex.findall(data.decode("utf-8"))
9497

9598
for key, value in kvs:
9699
self.handle_kv(key, value)
@@ -112,8 +115,12 @@ class MockTestEnvironment(object):
112115

113116
def __init__(self, test_case, platform_info, image_path):
114117
self._test_case = test_case
115-
self._platform_info = platform_info
116-
self._image_path = image_path
118+
self._tempdir = tempfile.mkdtemp()
119+
self._platform_info = copy(platform_info)
120+
self._platform_info['mount_point'] = os.path.join(self._tempdir, self._platform_info['mount_point'])
121+
self._platform_info['serial_port'] = os.path.join(self._tempdir, self._platform_info['serial_port'])
122+
self._image_path = os.path.join(self._tempdir, image_path)
123+
117124
self._patch_definitions = []
118125
self.patches = {}
119126

@@ -161,8 +168,11 @@ def patch(self, path, **kwargs):
161168
self._patch_definitions.append((path, patch(path, **kwargs)))
162169

163170
def __enter__(self):
164-
self._test_case.fs.create_file(self._image_path)
165-
self._test_case.fs.create_dir(self._platform_info['mount_point'])
171+
os.makedirs(os.path.dirname(self._image_path))
172+
with open(self._image_path, 'w') as _:
173+
pass
174+
175+
os.makedirs(self._platform_info['mount_point'])
166176

167177
for path, patcher in self._patch_definitions:
168178
self.patches[path] = patcher.start()
@@ -171,6 +181,8 @@ def __exit__(self, type, value, traceback):
171181
for _, patcher in self._patch_definitions:
172182
patcher.stop()
173183

184+
shutil.rmtree(self._tempdir)
185+
174186
class MockTestEnvironmentPosix(MockTestEnvironment):
175187

176188
def __init__(self, test_case, platform_info, image_path):
@@ -280,20 +292,14 @@ def __exit__(self, type, value, traceback):
280292
mock_platform_info = {
281293
"platform_name": "K64F",
282294
"target_id": "0240000031754e45000c0018948500156461000097969900",
283-
"mount_point": os.path.normpath("/mnt/DAPLINK"),
284-
"serial_port": os.path.normpath("/dev/ttyACM0"),
295+
"mount_point": os.path.normpath("mnt/DAPLINK"),
296+
"serial_port": os.path.normpath("dev/ttyACM0"),
285297
}
286298
mock_image_path = os.path.normpath(
287299
"BUILD/tests/K64F/GCC_ARM/TESTS/network/interface/interface.bin"
288300
)
289301

290-
class BlackBoxHostTestTestCase(fake_filesystem_unittest.TestCase):
291-
292-
def setUp(self):
293-
self.setUpPyfakefs()
294-
295-
def tearDown(self):
296-
pass
302+
class BlackBoxHostTestTestCase(unittest.TestCase):
297303

298304
def test_host_test_linux(self):
299305
with MockTestEnvironmentLinux(self, mock_platform_info, mock_image_path) as _env:

0 commit comments

Comments
 (0)