Skip to content

Commit 35c8547

Browse files
mcsprhasenradball
authored andcommitted
Fix python warnings and update device tests runner (esp8266#8623)
Update soon-to-be deprecated code in the runner.py https://docs.python.org/3/library/imp.html is deprecated since 3.4, will be removed in 3.12 https://docs.python.org/3/library/configparser.html readfp() is replaced with read_file() since 3.2, will be removed in 3.12 Use venv instead of virtualenv. We don't really use any of the extended features, and might as well simplify installation requirements. virtualenv/bin/python can execute runner.py inside of venv, no need to activate beforehand.
1 parent 4f608ec commit 35c8547

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

tests/device/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ $(TEST_LIST):
6565
ifeq ("$(MOCK)", "1")
6666
@echo Compiling $(notdir $@)
6767
(cd ../host; make D=$(V) ULIBDIRS=../device/libraries/BSTest ../device/$(@:%.ino=%))
68-
$(SILENT)source $(BS_DIR)/virtualenv/bin/activate && \
69-
$(PYTHON) $(BS_DIR)/runner.py \
68+
$(SILENT)$(BS_DIR)/virtualenv/bin/python \
69+
$(BS_DIR)/runner.py \
7070
$(RUNNER_DEBUG_FLAG) \
7171
-e "$(ESP8266_CORE_PATH)/tests/host/bin/$(@:%.ino=%)" \
7272
-n $(basename $(notdir $@)) \
@@ -120,8 +120,8 @@ ifneq ("$(NO_RUN)","1")
120120
--port $(UPLOAD_PORT) \
121121
--baud $(UPLOAD_BAUD) \
122122
read_flash_status $(REDIR) # reset
123-
$(SILENT)source $(BS_DIR)/virtualenv/bin/activate && \
124-
$(PYTHON) $(BS_DIR)/runner.py \
123+
$(SILENT)$(BS_DIR)/virtualenv/bin/python \
124+
$(BS_DIR)/runner.py \
125125
$(RUNNER_DEBUG_FLAG) \
126126
-p $(UPLOAD_PORT) \
127127
-n $(basename $(notdir $@)) \

tests/device/libraries/BSTest/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ clean:
1111
rm -rf $(TEST_EXECUTABLE)
1212

1313
$(PYTHON_ENV_DIR):
14-
virtualenv --python=$(PYTHON) --no-site-packages $(PYTHON_ENV_DIR)
15-
. $(PYTHON_ENV_DIR)/bin/activate && pip install -r requirements.txt
14+
$(PYTHON) -mvenv $(PYTHON_ENV_DIR)
15+
$(PYTHON_ENV_DIR)/bin/pip install -r requirements.txt
1616

1717
test: $(TEST_EXECUTABLE) $(PYTHON_ENV_DIR)
18-
. $(PYTHON_ENV_DIR)/bin/activate && $(PYTHON) runner.py -e $(TEST_EXECUTABLE) -m test/test.py
18+
$(PYTHON_ENV_DIR)/bin/python runner.py -e $(TEST_EXECUTABLE) -m test/test.py
1919

2020
$(TEST_EXECUTABLE): test/test.cpp
2121
g++ -std=c++11 -Isrc -o $@ test/test.cpp

tests/device/libraries/BSTest/runner.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import argparse
99
import serial
1010
import subprocess
11-
import imp
11+
12+
from importlib.machinery import SourceFileLoader
13+
1214
try:
1315
from configparser import ConfigParser
1416
except:
@@ -278,12 +280,12 @@ def main():
278280
if args.env_file is not None:
279281
cfg = ConfigParser()
280282
cfg.optionxform = str
281-
with args.env_file as fp:
282-
cfg.readfp(fp)
283+
with args.env_file as env:
284+
cfg.read_file(env)
283285
env_vars = cfg.items('global')
284286
mocks = {}
285287
if args.mock is not None:
286-
mocks_mod = imp.load_source('mocks', args.mock)
288+
mocks_mod = SourceFileLoader('mocks', args.mock).load_module()
287289
mocks = mock_decorators.env
288290
with spawn_func(spawn_arg) as sp:
289291
ts = run_tests(sp, name, mocks, env_vars)

0 commit comments

Comments
 (0)