Skip to content
Snippets Groups Projects
Commit b0002d18 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix unit tests

parent e8cb53e2
No related branches found
No related tags found
No related merge requests found
import functools
import operator
import typing as tp
from abc import ABCMeta, abstractmethod
......@@ -40,35 +41,32 @@ class ZerothSeverity(BaseCondition):
class OperationJoin(BaseCondition):
__slots__ = ('conditions',)
_OPERATOR = lambda y, z: y and z # pylint: disable=invalid-name
_STARTING_VALUE = False # pylint: disable=invalid-name
def __init__(self, *conditions: BaseCondition):
self.conditions = conditions
def can_fire(self, local_memory_data, local_maximum_consume: tp.Optional[int]) -> bool:
return functools.reduce(self.OPERATOR, (
return functools.reduce(self._OPERATOR, (
condition.can_fire(local_memory_data, local_maximum_consume) for condition in
self.conditions), self.STARTING_VALUE)
self.conditions), self._STARTING_VALUE)
class Any(OperationJoin):
"""This is true if one of the arguments is True"""
__slots__ = ()
@staticmethod
def OPERATOR(a, b):
return a or b
STARTING_VALUE = False
_OPERATOR = operator.or_
_STARTING_VALUE = False
class All(OperationJoin):
"""This is true if all arguments are True"""
__slots__ = ()
@staticmethod
def OPERATOR(a, b):
return a and b
STARTING_VALUE = True
_OPERATOR = operator.and_
_STARTING_VALUE = True
class Not(BaseCondition):
......
......@@ -129,7 +129,7 @@ class TestMemory(unittest.TestCase):
self.assertEqual(a['mem_normal'], 1)
a['level_2_engaged'] = True
time.sleep(3)
self.assertEqual(MemoryPressureManager().objects_to_cleanup_on_entered[1], [])
self.assertLessEqual(len(MemoryPressureManager().objects_to_cleanup_on_entered[1]), 1)
self.assertEqual(MemoryPressureManager().severity_level, 2)
self.assertEqual(a['cancelled'], 1)
self.assertEqual(a['times_entered_1'], 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment