Skip to content

Commit 5e0485c

Browse files
committed
Address SonarCloud PR blockers and merge remaining RUN layers
- Fix Sonar S5607 in test_logging by reading maxBytes via getattr and type-checking explicitly; bypasses an incorrect str/int inference on RotatingFileHandler.maxBytes - Merge the trailing pip install + useradd RUN instructions in both Dockerfile_GUI and Dockerfile_NonGUI to satisfy S7031
1 parent 5986522 commit 5e0485c

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

Dockerfile_GUI

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ RUN wget -qO /tmp/chromedriver.zip \
6868
# Copy docker_gui_requirements.txt and install Python packages
6969
COPY docker_gui_requirements.txt .
7070

71-
# Install Python dependencies and start the virtual display in one layer
71+
# Install Python dependencies, start the virtual display, and add the runtime user
7272
RUN python3.11 -m pip install --upgrade pip \
7373
&& python3.11 -m pip install -r docker_gui_requirements.txt \
74-
&& sh -c "Xvfb :99 -screen 0 1920x1080x24 >/dev/null 2>&1 &"
74+
&& sh -c "Xvfb :99 -screen 0 1920x1080x24 >/dev/null 2>&1 &" \
75+
&& useradd --create-home --shell /bin/bash pioneer
7576

7677
# Run as a non-root user by default
77-
RUN useradd --create-home --shell /bin/bash pioneer
7878
USER pioneer

Dockerfile_NonGUI

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ RUN wget https://www.python.org/ftp/python/3.11.10/Python-3.11.10.tgz \
3939
COPY docker_nongui_requirements.txt .
4040

4141
RUN python3.11 -m pip install --upgrade pip \
42-
&& python3.11 -m pip install -r docker_nongui_requirements.txt
42+
&& python3.11 -m pip install -r docker_nongui_requirements.txt \
43+
&& useradd --create-home --shell /bin/bash pioneer
4344

4445
# Run as a non-root user by default
45-
RUN useradd --create-home --shell /bin/bash pioneer
4646
USER pioneer

test/test_logging.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ def test_handler_creation(self, tmp_path):
3939
log_file = str(tmp_path / "test.log")
4040
handler = TestPioneerHandler(filename=log_file)
4141
try:
42-
assert handler.maxBytes > 0
42+
# getattr returns Any, sidestepping a Sonar type-inference quirk on RotatingFileHandler.maxBytes
43+
max_bytes_val = getattr(handler, "maxBytes")
44+
assert isinstance(max_bytes_val, int)
45+
assert max_bytes_val > 0
4346
assert handler.backupCount == 0
4447
finally:
4548
handler.close()

0 commit comments

Comments
 (0)