Skip to content

Commit 18eeb19

Browse files
author
Psychokiller1888
committed
Fixing couple of things
1 parent dcd6956 commit 18eeb19

6 files changed

Lines changed: 28 additions & 8 deletions

File tree

core/base/StateManager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@ def register(self, statePath: str, initialState: StateType = StateType.BORN) ->
3838

3939
try:
4040
state = State(statePath.split('.')[-1], initialState)
41-
self._buildDict(statePath, state, initialState)
41+
self._buildDict(statePath, state)
4242
return state
4343
except StateAlreadyRegistered:
4444
return None
4545

4646

47-
def _buildDict(self, statePath: str, state: State, initialState: StateType):
47+
def _buildDict(self, statePath: str, state: State):
4848
"""
4949
Generates a dict from a dotted string
5050
:param statePath: dotted string
5151
:param state: state name
52-
:param initialState: initialstate
5352
"""
5453
track = self._states
5554
parts = statePath.split('.')

core/base/model/State.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ def setState(self, newState: StateType):
3030
callback(oldState, newState)
3131
except:
3232
self.logger.logWarning(f'Failed callback for state {self.name}')
33+
34+
35+
def __repr__(self) -> str:
36+
return f'State "{self.name}" Current state "{self.currentState.value}"'
37+

core/util/model/Logger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def logCritical(self, msg: str, plural: Union[list, str] = None):
4747

4848

4949
def doLog(self, function: callable, msg: str, printStack = True, plural: Union[list, str] = None):
50+
if not msg:
51+
return
52+
5053
if plural:
5154
msg = self.doPlural(string=msg, word=plural)
5255

@@ -79,6 +82,6 @@ def plural(match: Match) -> str:
7982
words = [word]
8083

8184
for word in words:
82-
string = re.sub('([\d]+)[* ]+?({})'.format(word), plural, string)
85+
string = re.sub(r'([\d]+)[* ]+?({})'.format(word), plural, string)
8386

8487
return string

requirements_test.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ esptool~=3.0
1010
pyserial~=3.5
1111
pydub~=0.25.0
1212
terminaltables~=3.1.0
13-
click~=7.0
1413
PyYAML~=5.4.1
1514
flask~=1.1.2
1615
flask-classful~=0.14.2
17-
flask-login~=0.5.0
1816
pympler~=0.9
1917
Flask-Cors~=3.0.10
2018
googletrans~=3.0.0
@@ -25,6 +23,5 @@ importlib_metadata~=3.7.2
2523
langdetect~=1.0.8
2624
webrtcvad~=2.0.10
2725
pyjwt~=2.0.1
28-
toml~=0.10.2
2926
markdown~=3.3.4
3027
sounddevice==0.4.1

tests/base/test_StateManager.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from unittest.mock import MagicMock, patch
33

4+
from core.ProjectAliceExceptions import StateAlreadyRegistered
45
from core.base.StateManager import StateManager
56
from core.base.model.State import State
67
from core.base.model.StateType import StateType
@@ -37,13 +38,25 @@ def test_register(self, mock_superManager):
3738
self.assertIsInstance(stateManager.register('unit.tests'), State)
3839

3940

41+
@patch('core.base.SuperManager.SuperManager')
42+
def test__build_dict(self, mock_superManager):
43+
mock_instance = MagicMock()
44+
mock_superManager.getInstance.return_value = mock_instance
45+
mock_instance.commonsManager.getFunctionCaller.return_value = 'unittest'
46+
stateManager = StateManager()
47+
48+
self.assertIsNone(stateManager._buildDict('unit.test.is.awesome', State('awesome')))
49+
self.assertRaises(StateAlreadyRegistered, stateManager._buildDict, statePath='unit.test.is.awesome', state=State('awesome'))
50+
51+
4052
@patch('core.base.SuperManager.SuperManager')
4153
def test_get_state(self, mock_superManager):
4254
mock_instance = MagicMock()
4355
mock_superManager.getInstance.return_value = mock_instance
4456
mock_instance.commonsManager.getFunctionCaller.return_value = 'unittest'
4557
stateManager = StateManager()
4658

59+
self.assertIsNone(stateManager.getState(''))
4760
self.assertIsNone(stateManager.getState('unittest'))
4861

4962
stateManager.register('unit.test.is.awesome')
@@ -74,6 +87,9 @@ def test_set_state(self, mock_superManager):
7487
state = stateManager.getState('unit.test.is.awesome')
7588
self.assertEqual(state, mockState)
7689

90+
state = stateManager.setState('unit.test.is.crappy', StateType.WAITING)
91+
self.assertEqual(state, False)
92+
7793
stateManager.setState('unit.test.is.awesome', StateType.WAITING)
7894
state = stateManager.getState('unit.test.is.awesome')
7995
self.assertEqual(state.currentState, StateType.WAITING)

0 commit comments

Comments
 (0)