Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Fix tests for travis-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Dec 30, 2016
1 parent be540c6 commit 5d94966
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 34 deletions.
4 changes: 3 additions & 1 deletion wpilib/testing-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
-e ../hal-base
-e ../hal-sim

git+git://github.com/robotpy/pynetworktables.git
git+git://github.com/robotpy/pyfrc.git

pytest>=2.8
coverage
pyfrc
CppHeaderParser>=2.7.4
7 changes: 7 additions & 0 deletions wpilib/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

import sys
import pytest
from unittest.mock import MagicMock, patch

Expand All @@ -7,6 +9,8 @@ def _module_patch(request):

assert 'halmock' not in request.fixturenames, "Cannot use mock and real fixtures in same function!"

assert 'wpilib' not in sys.modules, "Must use wpilib fixture, don't import wpilib directly"

# .. this seems inefficient

m = patch.dict('sys.modules', {})
Expand Down Expand Up @@ -39,6 +43,9 @@ def wpilib(_module_patch, hal, hal_data):
import wpilib
return wpilib

# Note: we don't use wpilib.Resource._reset here because the wpilib module
# is freshly loaded each time a new test is ran

@pytest.fixture(scope="function")
def networktables():
"""Networktables instance"""
Expand Down
31 changes: 1 addition & 30 deletions wpilib/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,4 @@ abspath() {
# Not strictly necessary if testing-requirements was installed...
PYTHONPATH=$(abspath ./..):$(abspath ../../hal-sim):$(abspath ../../hal-base):$PYTHONPATH

python3 -m coverage run --source wpilib -m pytest $@
python -m coverage report -m


EXAMPLES="
iterative/
sample/
test/
examples/CANTalon/
examples/CANTalonPID/
examples/CANTalonVelocityClosedLoop/
examples/GearsBot/
examples/GettingStarted/
examples/MecanumDrive/
examples/MotorControl/
examples/Gyro/
examples/pacgoat/
examples/QuickVision/
examples/TankDrive/
"

if [ -z "${NOPYFRC}" ]; then
for example in $EXAMPLES; do
pushd ../../examples/$example
python3 robot.py test --builtin
popd
done
fi

PYTHONPATH="$PYTHONPATH" python3 -m pytest $@
42 changes: 42 additions & 0 deletions wpilib/tests/run_travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -e
cd `dirname $0`

abspath() {
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}

# Not strictly necessary if testing-requirements was installed...
PYTHONPATH=$(abspath ./..):$(abspath ../../hal-sim):$(abspath ../../hal-base):$PYTHONPATH

python3 -m coverage run --source wpilib -m pytest $@
python -m coverage report -m


EXAMPLES="
iterative/
sample/
test/
examples/CANTalon/
examples/CANTalonPID/
examples/CANTalonVelocityClosedLoop/
examples/GearsBot/
examples/GettingStarted/
examples/MecanumDrive/
examples/MotorControl/
examples/Gyro/
examples/pacgoat/
examples/QuickVision/
examples/TankDrive/
"

if [ -z "${NOPYFRC}" ]; then
for example in $EXAMPLES; do
pushd ../../examples/$example
python3 robot.py test --builtin
popd
done
fi

4 changes: 1 addition & 3 deletions wpilib/tests/test_lineardigitalfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import random
from unittest.mock import MagicMock

from wpilib.interfaces.pidsource import PIDSource

# Filter constants taken from Java WPILIB
# allwpilib/blob/master/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/TestBench.java

Expand All @@ -27,7 +25,7 @@ def reset(self):
self.pid_idx = 0

def getPIDSourceType(self):
return PIDSource.PIDSourceType.kDisplacement
assert False

def pidGet(self):
self.pid_idx += 1
Expand Down

0 comments on commit 5d94966

Please sign in to comment.