Skip to content

Commit

Permalink
Refactor GitHub Actions and display handling for integration tests
Browse files Browse the repository at this point in the history
- Update test.yml workflow to directly configure virtual display
- Remove redundant GabrielBB/xvfb-action and simplify test setup
- Enhance run_mouse_policy.py display environment configuration
- Add robust handling for headless testing environments
  • Loading branch information
beduffy committed Feb 22, 2025
1 parent adb7495 commit cdd2bc3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y xvfb x11-utils xserver-xorg-video-dummy libgl1-mesa-glx
- name: Configure virtual display
run: |
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
echo "DISPLAY=:99" >> $GITHUB_ENV
echo "XAUTHORITY=/tmp/.Xauthority" >> $GITHUB_ENV
xauth generate :99 . trusted
xauth add $(xauth list | tail -1)
- name: Run integration tests
run: |
pytest -m integration --cov=./ --cov-report=xml
- name: Cache pip packages
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -58,22 +75,12 @@ jobs:
# - name: Check import sorting with isort
# run: isort --check-only --diff .

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y xvfb libgtk-3-dev libx11-xcb1 libxss1 libgconf-2-4 libnss3 libasound2
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pyautogui
- name: Run integration tests with virtual display
uses: GabrielBB/xvfb-action@v1
with:
run: pytest -m integration --cov=./ --cov-report=xml

- name: Run tests with coverage
run: |
pytest tests/unit -v --cov=./ --cov-report=xml
Expand Down
15 changes: 9 additions & 6 deletions imitate_mouse/run_mouse_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

from imitate_mouse.imitate_mouse import MouseRecorder, ACTPolicy

# Only import pyautogui if we have a display
if os.name == 'posix' and 'DISPLAY' not in os.environ:
os.environ['DISPLAY'] = ':99' # Match Xvfb display number
if 'DISPLAY' in os.environ or 'PYTEST_CURRENT_TEST' in os.environ:
# Configure display for headless environments
if os.name == 'posix' and not os.environ.get('DISPLAY'):
os.environ['DISPLAY'] = ':99'
os.environ['XAUTHORITY'] = '/tmp/.Xauthority'

try:
import pyautogui
else:
pyautogui = None # Mock for headless environments
from Xlib.display import Display
except ImportError:
pyautogui = None


def run_policy_eval(args, num_steps=100):
Expand Down

0 comments on commit cdd2bc3

Please sign in to comment.