cooptools 1.78__tar.gz → 1.79__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cooptools-1.78 → cooptools-1.79}/PKG-INFO +1 -1
- {cooptools-1.78 → cooptools-1.79}/cooptools/commandDesignPattern/commandController.py +16 -11
- {cooptools-1.78 → cooptools-1.79}/cooptools.egg-info/PKG-INFO +1 -1
- {cooptools-1.78 → cooptools-1.79}/setup.py +1 -1
- {cooptools-1.78 → cooptools-1.79}/tests/test_commandDesignPattern.py +112 -1
- {cooptools-1.78 → cooptools-1.79}/MANIFEST.in +0 -0
- {cooptools-1.78 → cooptools-1.79}/README.md +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/anchor.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/asyncable.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/cli/CliAtomicUserInteraction.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/cli/CliMenu.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/cli/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/cli/fileContentReturn.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/cnxn_info.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/colors.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/commandDesignPattern/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/commandDesignPattern/commandProtocol.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/commandDesignPattern/exceptions.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/common.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/config.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/coopDataclass.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/coopEnum.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/coopthreading.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/currency.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dataRefresher/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dataRefresher/dataHub.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dataRefresher/dataRefresher.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dataStore/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dataStore/dataProcessor.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dataStore/dataStoreProtocol.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dataStore/dbConnectionURI.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dataStore/inMemoryDataStore.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/date_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/decay.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/decor.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/dictPolicies.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/exceptions.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/expertise/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/expertise/expertiseArgs.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/expertise/expertiseSchedules.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/expertise/expertise_state.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/finance/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/finance/dicounted_cashflow_analysis.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/finance/fund_projection.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/finance/fund_projection_renderer.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/finance/futureValueProjector.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/finance/growth_projections.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/finance/reports.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/finance/utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/circle_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/common.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/curve_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/curves.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/line_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/polygon_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/rect_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/triangle_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/geometry_utils/vector_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/graphs/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/graphs/astar_results_viewer.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/graphs/draw.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/graphs/flow_field.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/graphs/graph.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/graphs/graph_dcs.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/graphs/graph_definitions.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/graphs/utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/actionItemTracker/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/actionItemTracker/ai_tracker.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/actionItemTracker/dcs.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/discreteEventSimulator/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/discreteEventSimulator/discreteEventSimulator.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/jsonIO.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/metrics.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/triggerActionSystem/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/triggerActionSystem/signal.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/ideas/triggerActionSystem/trigger.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/loggingHelpers.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/marchingSquares.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/materialHandling/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/materialHandling/cli.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/materialHandling/dcs.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/materialHandling/selectionCriteria.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/matrixManipulation.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/os_manip.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pandasHelpers.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/catmullRomFollower.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/demo/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/demo/server.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/kinematicGoalSeeker.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/motion_profile_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/orbit_fuzzer.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/path_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/straightLineFollower.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/trajectory_provider.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/waypoint.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/pathing/waypointFollower.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/persistence/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/persistence/enum_state.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/persistence/stateful.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/physics/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/physics/kinematic.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/physics/kinematic_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/physics/movement.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/physics/trajectory.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/plotting.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/printing.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/protocols.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/qualifiers/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/qualifiers/cli.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/qualifiers/qualifier.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/randoms.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/register.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/reservation/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/reservation/dcs.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/reservation/enums.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/reservation/reservationmanager.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/retry.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/grids/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/grids/gridState.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/grids/grid_base.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/grids/hexGrid.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/grids/rectGrid.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/hex_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/sect_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/sectorTree/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/sectors/sectorTree/sectorTree.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/statistics/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/statistics/activityReport.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/statistics/controlChart/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/statistics/controlChart/controlChart.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/statistics/controlChart/plotting.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/statistics/oee/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/statistics/oee/oeeHub.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/taskProcessing/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/taskProcessing/dcs.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/taskProcessing/taskProcessor.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/timeTracker/__init__.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/timeTracker/decay.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/timeTracker/timeTracker.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/timeWindow.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/toggles.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/transform.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/trends.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/typeProviders.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/typevalidation.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools/version.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools.egg-info/SOURCES.txt +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools.egg-info/dependency_links.txt +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools.egg-info/not-zip-safe +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools.egg-info/requires.txt +0 -0
- {cooptools-1.78 → cooptools-1.79}/cooptools.egg-info/top_level.txt +0 -0
- {cooptools-1.78 → cooptools-1.79}/requirements.txt +0 -0
- {cooptools-1.78 → cooptools-1.79}/setup.cfg +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_CliAtomicUserInteraction.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_asyncable.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_catmullRomFollower.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_cdp_bugs.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_common.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_config.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_coopEnum.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_currency.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_curves.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_date_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_expertise_state.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_flow_field.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_flow_field_perf.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_fund_projection.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_graph_node_classification.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_kinematicGoalSeeker.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_kinematic_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_os_manip.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_pandas.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_path_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_persistence.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_printing.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_qualifiers.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_sectors.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_sectors_hex.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_sectors_sectorTree.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_statistics.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_straightLineFollower.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_target_seek.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_tasks.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_toggles.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_trajectory.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_trends.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_typevalidation.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_vector_utils.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_version.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/test_waypointFollower.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/tests_graph.py +0 -0
- {cooptools-1.78 → cooptools-1.79}/tests/tests_gridsystem.py +0 -0
|
@@ -51,8 +51,8 @@ class CommandStore(Protocol):
|
|
|
51
51
|
return last_cached_state, max_cached_idx
|
|
52
52
|
|
|
53
53
|
def clear_cache(self):
|
|
54
|
-
|
|
55
|
-
for cursor in
|
|
54
|
+
# the keys are snapshotted because remove_cached_at_cursor mutates the dict get_cached returns
|
|
55
|
+
for cursor in list(self.get_cached().keys()):
|
|
56
56
|
self.remove_cached_at_cursor(cursor)
|
|
57
57
|
|
|
58
58
|
def clear_commands(self):
|
|
@@ -120,15 +120,13 @@ class CommandController:
|
|
|
120
120
|
self._live_state = copy.deepcopy(self.init_state)
|
|
121
121
|
self.command_store.add_cached(copy.deepcopy(self._live_state), self.cursor)
|
|
122
122
|
else:
|
|
123
|
+
# the cursor has to land before the resolve, because resolve() replays up to it; a store
|
|
124
|
+
# restored from persistence otherwise resolves at 0 and hands back the (absent) init state
|
|
125
|
+
self.cursor = len(self.command_store.get_commands(start_cursor=idx)) + idx
|
|
123
126
|
self._live_state = self.resolve()
|
|
124
127
|
|
|
125
128
|
logger.info(f"Init State: {pprint.pformat(self._live_state)}")
|
|
126
129
|
|
|
127
|
-
if idx is None:
|
|
128
|
-
self.cursor = 0
|
|
129
|
-
else:
|
|
130
|
-
self.cursor = len(self.command_store.get_commands(start_cursor=idx)) + idx
|
|
131
|
-
|
|
132
130
|
def _needsLock(foo):
|
|
133
131
|
def magic(self, *args, **kwargs):
|
|
134
132
|
with self._lock:
|
|
@@ -140,8 +138,9 @@ class CommandController:
|
|
|
140
138
|
|
|
141
139
|
@_needsLock
|
|
142
140
|
def execute(self, commands: List[CommandProtocol]) -> T:
|
|
143
|
-
#
|
|
144
|
-
|
|
141
|
+
# a cursor of N means N commands have been applied, so the active commands are exactly
|
|
142
|
+
# the first N in the store and anything from N onward is a branch being discarded
|
|
143
|
+
self.command_store.remove_commands(self.cursor)
|
|
145
144
|
|
|
146
145
|
# delete any cached states after the current cursor
|
|
147
146
|
stale = [ii for ii in self.command_store.get_cached() if ii > self.cursor]
|
|
@@ -165,10 +164,12 @@ class CommandController:
|
|
|
165
164
|
except Exception as e:
|
|
166
165
|
self._live_state = pre_batch_state
|
|
167
166
|
self.cursor = pre_batch_cursor
|
|
168
|
-
self.command_store.remove_commands(pre_batch_cursor
|
|
167
|
+
self.command_store.remove_commands(pre_batch_cursor)
|
|
169
168
|
raise ResolveStateException(command=command, inner=e) from e
|
|
170
169
|
|
|
171
|
-
|
|
170
|
+
cached_cursors = self.command_store.get_cached().keys()
|
|
171
|
+
last_cached_cursor = max(cached_cursors) if cached_cursors else 0
|
|
172
|
+
if self.cursor - last_cached_cursor >= self.cache_interval:
|
|
172
173
|
self.command_store.add_cached(copy.deepcopy(self._live_state), self.cursor)
|
|
173
174
|
|
|
174
175
|
return self._live_state
|
|
@@ -180,6 +181,10 @@ class CommandController:
|
|
|
180
181
|
idx = self.cursor
|
|
181
182
|
|
|
182
183
|
if idx == 0:
|
|
184
|
+
# a store restored from persistence has a cursor-0 snapshot but no init_state in hand
|
|
185
|
+
cached_at_origin = self.command_store.get_cached().get(0, None)
|
|
186
|
+
if cached_at_origin is not None:
|
|
187
|
+
return copy.deepcopy(cached_at_origin)
|
|
183
188
|
return copy.deepcopy(self.init_state)
|
|
184
189
|
|
|
185
190
|
try:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import unittest
|
|
2
|
-
from cooptools.commandDesignPattern import CommandBatch, CommandProtocol, CommandController
|
|
2
|
+
from cooptools.commandDesignPattern import CommandBatch, CommandProtocol, CommandController, InMemoryCommandStore
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
from cooptools.commandDesignPattern.exceptions import ResolveBatchException, ResolveStateException
|
|
5
5
|
|
|
@@ -23,6 +23,13 @@ class Dummy_CommandThatFails(CommandProtocol):
|
|
|
23
23
|
def execute(self, state):
|
|
24
24
|
raise Exception(f"Dummy Exception")
|
|
25
25
|
|
|
26
|
+
@dataclass
|
|
27
|
+
class Dummy_PureCommand(CommandProtocol):
|
|
28
|
+
adjustment: int
|
|
29
|
+
|
|
30
|
+
def execute(self, state):
|
|
31
|
+
return Dummy_State(amount=state.amount + self.adjustment)
|
|
32
|
+
|
|
26
33
|
class Test_CommandDesignPattern(unittest.TestCase):
|
|
27
34
|
|
|
28
35
|
def test__register_commands(self):
|
|
@@ -181,3 +188,107 @@ class Test_CommandDesignPattern(unittest.TestCase):
|
|
|
181
188
|
# assert
|
|
182
189
|
self.assertRaises(ResolveStateException, lambda: controller.execute(commands=commands))
|
|
183
190
|
|
|
191
|
+
def test__execute_after_undo__discards_the_abandoned_branch(self):
|
|
192
|
+
# arrange
|
|
193
|
+
controller = CommandController(Dummy_State())
|
|
194
|
+
controller.execute([Dummy_PureCommand(adjustment=100)])
|
|
195
|
+
controller.execute([Dummy_PureCommand(adjustment=200)])
|
|
196
|
+
controller.undo()
|
|
197
|
+
|
|
198
|
+
# act
|
|
199
|
+
controller.execute([Dummy_PureCommand(adjustment=999)])
|
|
200
|
+
|
|
201
|
+
# assert
|
|
202
|
+
self.assertEqual(controller.ActiveCommands,
|
|
203
|
+
[Dummy_PureCommand(adjustment=100), Dummy_PureCommand(adjustment=999)])
|
|
204
|
+
self.assertEqual(controller.cursor, 2)
|
|
205
|
+
|
|
206
|
+
def test__execute_after_undo__live_state_matches_resolved_state(self):
|
|
207
|
+
# arrange
|
|
208
|
+
controller = CommandController(Dummy_State())
|
|
209
|
+
controller.execute([Dummy_PureCommand(adjustment=100)])
|
|
210
|
+
controller.execute([Dummy_PureCommand(adjustment=200)])
|
|
211
|
+
controller.undo()
|
|
212
|
+
|
|
213
|
+
# act
|
|
214
|
+
controller.execute([Dummy_PureCommand(adjustment=999)])
|
|
215
|
+
|
|
216
|
+
# assert
|
|
217
|
+
self.assertEqual(controller.State.amount, 1099)
|
|
218
|
+
self.assertEqual(controller.resolve(controller.cursor).amount, controller.State.amount)
|
|
219
|
+
|
|
220
|
+
def test__failed_batch__leaves_no_commands_in_the_store(self):
|
|
221
|
+
# arrange
|
|
222
|
+
controller = CommandController(Dummy_State())
|
|
223
|
+
|
|
224
|
+
# act
|
|
225
|
+
self.assertRaises(ResolveStateException, lambda: controller.execute(
|
|
226
|
+
[Dummy_PureCommand(adjustment=1000), Dummy_CommandThatFails(adjustment=500)]))
|
|
227
|
+
|
|
228
|
+
# assert
|
|
229
|
+
self.assertEqual(controller.command_store.get_commands(), [])
|
|
230
|
+
self.assertEqual(controller.cursor, 0)
|
|
231
|
+
|
|
232
|
+
def test__execute_after_failed_batch__live_state_matches_resolved_state(self):
|
|
233
|
+
# arrange
|
|
234
|
+
controller = CommandController(Dummy_State())
|
|
235
|
+
self.assertRaises(ResolveStateException, lambda: controller.execute(
|
|
236
|
+
[Dummy_PureCommand(adjustment=1000), Dummy_CommandThatFails(adjustment=500)]))
|
|
237
|
+
|
|
238
|
+
# act
|
|
239
|
+
controller.execute([Dummy_PureCommand(adjustment=7)])
|
|
240
|
+
|
|
241
|
+
# assert
|
|
242
|
+
self.assertEqual(controller.State.amount, 7)
|
|
243
|
+
self.assertEqual(controller.resolve(controller.cursor).amount, controller.State.amount)
|
|
244
|
+
|
|
245
|
+
def test__clear_cache__removes_every_cached_state(self):
|
|
246
|
+
# arrange
|
|
247
|
+
controller = CommandController(Dummy_State(), cache_interval=1)
|
|
248
|
+
controller.execute([Dummy_PureCommand(adjustment=1)])
|
|
249
|
+
controller.execute([Dummy_PureCommand(adjustment=1)])
|
|
250
|
+
self.assertTrue(len(controller.command_store.get_cached()) > 1)
|
|
251
|
+
|
|
252
|
+
# act
|
|
253
|
+
controller.command_store.clear_cache()
|
|
254
|
+
|
|
255
|
+
# assert
|
|
256
|
+
self.assertEqual(controller.command_store.get_cached(), {})
|
|
257
|
+
|
|
258
|
+
def test__execute_with_no_cached_states__does_not_raise(self):
|
|
259
|
+
# arrange
|
|
260
|
+
controller = CommandController(Dummy_State())
|
|
261
|
+
controller.command_store.clear_cache()
|
|
262
|
+
|
|
263
|
+
# act
|
|
264
|
+
state = controller.execute([Dummy_PureCommand(adjustment=42)])
|
|
265
|
+
|
|
266
|
+
# assert
|
|
267
|
+
self.assertEqual(state.amount, 42)
|
|
268
|
+
|
|
269
|
+
def test__controller_restored_from_store__recovers_state_and_cursor(self):
|
|
270
|
+
# arrange
|
|
271
|
+
store = InMemoryCommandStore()
|
|
272
|
+
original = CommandController(Dummy_State(), command_store=store)
|
|
273
|
+
original.execute([Dummy_PureCommand(adjustment=100)])
|
|
274
|
+
original.execute([Dummy_PureCommand(adjustment=200)])
|
|
275
|
+
|
|
276
|
+
# act
|
|
277
|
+
restored = CommandController(command_store=store)
|
|
278
|
+
|
|
279
|
+
# assert
|
|
280
|
+
self.assertEqual(restored.State.amount, 300)
|
|
281
|
+
self.assertEqual(restored.cursor, original.cursor)
|
|
282
|
+
|
|
283
|
+
def test__controller_restored_from_store__undo_to_origin_returns_origin_state(self):
|
|
284
|
+
# arrange
|
|
285
|
+
store = InMemoryCommandStore()
|
|
286
|
+
original = CommandController(Dummy_State(), command_store=store)
|
|
287
|
+
original.execute([Dummy_PureCommand(adjustment=100)])
|
|
288
|
+
restored = CommandController(command_store=store)
|
|
289
|
+
|
|
290
|
+
# act
|
|
291
|
+
state = restored.undo()
|
|
292
|
+
|
|
293
|
+
# assert
|
|
294
|
+
self.assertEqual(state.amount, 0)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cooptools-1.78 → cooptools-1.79}/cooptools/ideas/discreteEventSimulator/discreteEventSimulator.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|