Skip to content

Commit

Permalink
Updated timer for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-carboni committed May 17, 2024
1 parent a77beb9 commit b33c2d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions simulators/minor_servos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import time
import re
import random
import os
try:
from numpy import sign
except ImportError as ex: # skip coverage
Expand All @@ -28,7 +27,7 @@
# subscribe and unsibscribe methods, while kwargs is a dict of optional
# extra arguments.
servers = [(('0.0.0.0', 12800), (), ThreadingTCPServer, {})]
TIMER_VALUE = 1 if os.environ.get('CI') == 'true' else 5
DEFAULT_TIMER_VALUE = 5


def _change_atomic_value(variable, value):
Expand Down Expand Up @@ -76,7 +75,7 @@ def plc_time(now=None):
'BWG4': {'ID': 24},
}

def __init__(self):
def __init__(self, timer_value=DEFAULT_TIMER_VALUE):
self.msg = ''
self.configuration = 0
self.simulation = 1
Expand All @@ -86,6 +85,7 @@ def __init__(self):
self.emergency = 2
self.gregorian_cap = Value(c_int, 1)
self.last_executed_command = 0
self.timer_value = timer_value
self.servos = {
'PFP': PFP(),
'SRP': SRP(),
Expand Down Expand Up @@ -189,7 +189,7 @@ def _setup(self, args):
servo.operative_mode_timer.cancel()
_change_atomic_value(servo.operative_mode, 0)
servo.operative_mode_timer = Timer(
TIMER_VALUE,
self.timer_value,
_change_atomic_value,
args=(servo.operative_mode, 10) # SETUP
)
Expand All @@ -199,7 +199,7 @@ def _setup(self, args):
if self.gregorian_cap.value != gregorian_cap_position:
_change_atomic_value(self.gregorian_cap, 0)
self.cover_timer = Timer(
TIMER_VALUE,
self.timer_value,
_change_atomic_value,
args=(self.gregorian_cap, gregorian_cap_position)
)
Expand All @@ -224,7 +224,7 @@ def _stow(self, args):
if self.gregorian_cap.value != stow_pos:
_change_atomic_value(self.gregorian_cap, 0)
self.cover_timer = Timer(
TIMER_VALUE,
self.timer_value,
_change_atomic_value,
args=(self.gregorian_cap, stow_pos)
)
Expand All @@ -235,7 +235,7 @@ def _stow(self, args):
servo.operative_mode_timer.cancel()
_change_atomic_value(servo.operative_mode, 0)
servo.operative_mode_timer = Timer(
TIMER_VALUE,
self.timer_value,
_change_atomic_value,
args=(servo.operative_mode, 20) # STOW
)
Expand All @@ -254,7 +254,7 @@ def _stop(self, args):
servo.operative_mode_timer.cancel()
_change_atomic_value(servo.operative_mode, 0)
servo.operative_mode_timer = Timer(
TIMER_VALUE,
self.timer_value,
_change_atomic_value,
args=(servo.operative_mode, 30) # STOP
)
Expand All @@ -281,7 +281,7 @@ def _preset(self, args):
servo.operative_mode_timer.cancel()
_change_atomic_value(servo.operative_mode, 0)
servo.operative_mode_timer = Timer(
TIMER_VALUE,
self.timer_value,
_change_atomic_value,
args=(servo.operative_mode, 40) # PRESET
)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_minor_servos.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import unittest
import random
import time
from simulators.minor_servos import System, TIMER_VALUE

from simulators.minor_servos import System

TIMER_VALUE = 0.01
tail = '\r\n'
good = r'^OUTPUT:GOOD,[0-9]+\.[0-9]{6}'
bad = f'^OUTPUT:BAD{tail}$'
Expand All @@ -12,7 +12,7 @@
class TestMinorServos(unittest.TestCase):

def setUp(self):
self.system = System()
self.system = System(timer_value=TIMER_VALUE)

def tearDown(self):
del self.system
Expand Down

0 comments on commit b33c2d1

Please sign in to comment.