Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional Testing with tests derived from xstate.core 4.25 #49

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
3f87eac
test: wip towards fix history_state
SLLau Sep 21, 2021
692a36e
test: wip history_state
SLLau Sep 21, 2021
44dee7a
feat: configuration as snippet of javascript
SLLau Sep 23, 2021
7eebefb
feat: history supporting functions, wip
SLLau Sep 23, 2021
877bed5
feat: configuration as snippet of javascript
SLLau Sep 23, 2021
6c7b975
feat: history --- wip
SLLau Sep 23, 2021
770e9c2
test: config as javasrcipt snippet
SLLau Sep 23, 2021
0b5bd7a
test: state_in and state test definitions --- wip
SLLau Sep 23, 2021
20006b7
refactor: type checking
SLLau Sep 24, 2021
b3e436a
tests: algorithm - statepath functions
SLLau Sep 24, 2021
ca8dbe9
fix: get_configuration_from_js from .algorithm
SLLau Sep 24, 2021
df81cad
fix: get_configuration_from_state for State or str
SLLau Sep 24, 2021
581ced0
fix:: machine initialize with duplicate default
SLLau Sep 25, 2021
e2c39b0
test: transitions - test 2 working
SLLau Sep 26, 2021
d45493d
test: state transition, test 3 with cond now pass
SLLau Sep 26, 2021
f08ac08
refactor: wip - actions ,code from xstate.core
SLLau Sep 27, 2021
f91b14c
refactor: actions code from xstate.core fix scxml
SLLau Sep 27, 2021
98c0f60
refactor: black formatting - core
SLLau Sep 28, 2021
ddcde4e
refactor: black formatting - tests
SLLau Sep 28, 2021
c327e8a
refactor: fixes for circular imports
SLLau Sep 28, 2021
7d6f2c9
test: wip, test_algorithim_get_configuration
SLLau Sep 28, 2021
950c4e5
test: get_configuraion - working
SLLau Sep 29, 2021
7b79a9f
fix: initial (value) vs initial (transition)
SLLau Sep 30, 2021
04fc6b2
chore: fix class name typo
SLLau Sep 30, 2021
e60471e
fix: stateNode initial becoming initial_transition
SLLau Sep 30, 2021
4321d80
feat: class for js style functional tests
SLLau Sep 30, 2021
9013a23
tests: state in transition , first 3 tests
SLLau Sep 30, 2021
ded5aed
test: support for js style test adoption
SLLau Oct 4, 2021
10193d9
test: adopt all statein tests from xstate js
SLLau Oct 4, 2021
4ea87b0
feat: support for transitions using path defs
SLLau Oct 4, 2021
a5146e9
fix: node should be from root in machine
SLLau Oct 4, 2021
5f9a6c9
fix: for transition config being a dict
SLLau Oct 4, 2021
d4065d3
test: suppress statein that require guards feat.
SLLau Oct 5, 2021
bb67f73
chore: remove bug comments
SLLau Oct 5, 2021
a29329a
test: supress for not implement functionality
SLLau Oct 5, 2021
1c8ccc0
feat: wip history - saving
SLLau Oct 11, 2021
c1f6920
fix: update history value not correct prior
SLLau Oct 11, 2021
5893129
feat: history passing first unittest
SLLau Oct 12, 2021
cf25c7d
fix: history related updates affecting tests
SLLau Oct 12, 2021
f432b70
test: cleanup history first tests
SLLau Oct 12, 2021
19b0b7f
fix: assertion on transition count to restrictave
SLLau Oct 12, 2021
0009b5e
test: extending history testing - wip
SLLau Oct 12, 2021
96e7193
test: extending history testing - wip
SLLau Oct 12, 2021
b3b9c87
fix: penultimate history purging
SLLau Oct 12, 2021
785d2bd
test: history on eventless always transition
SLLau Oct 13, 2021
76f199a
fix: state by custom id ie `#the_state`
SLLau Oct 13, 2021
824317d
test: wip history deep and shallow
SLLau Oct 13, 2021
31a6ff8
test: history deep and shallow
SLLau Oct 13, 2021
818673f
test: wip on history parallel
SLLau Oct 13, 2021
e8df727
fix, create State object if state is in a dict
SLLau Oct 15, 2021
3565d18
fix: default State context to None
SLLau Oct 15, 2021
9120037
test: improve test assert fail message
SLLau Oct 15, 2021
385fc55
fix: resolving fails in deep history tests
SLLau Oct 15, 2021
8deb48f
test: all remainder ParallelHist test per xstateJS
SLLau Oct 18, 2021
e64b4a2
fix: determing hist type from keywork being there
SLLau Oct 18, 2021
d641c2b
fix: for parallelhistory tests
SLLau Oct 18, 2021
aa6a46b
test: add transient history test from xstateJS
SLLau Oct 18, 2021
91acabc
test: add InternalTransitionWithHistory from xstateJS
SLLau Oct 18, 2021
be5cf9e
test: add MultistageHistoryStates as per XstateJS
SLLau Oct 18, 2021
b59a030
fix: history_value incorrectly port from XstateJS
SLLau Oct 18, 2021
3694329
fix: history_value mutable in other state
SLLau Oct 18, 2021
14eed92
fix: history_values not being eval in some tests
SLLau Oct 18, 2021
cab37af
test: history skip transient not yet supported
SLLau Oct 18, 2021
cc6688d
test: parallel history states, no 2 and 3 fixed
SLLau Oct 19, 2021
b8c5db6
fix: correctly process state id
SLLau Oct 19, 2021
8b41008
fix: history resolve for parallel and deep states
SLLau Oct 19, 2021
c4cc766
doc: cleanup and update TODO's
SLLau Oct 19, 2021
f1655ea
fix: code quality checks, black check failing
SLLau Oct 25, 2021
d68c3d6
fix: minimum python set to 3.7
SLLau Oct 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
poetry-version: [1.1.6]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
Expand Down
21 changes: 20 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ keywords = ["Answer Set Programming", "wrapper", "clingo"]
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9"
Expand All @@ -22,8 +21,9 @@ packages = [
docs = "https://github.com/davidkpiano/xstate-python"

[tool.poetry.dependencies]
python = "^3.6.2"
python = "^3.7.0"
Js2Py = "^0.71"
anytree = "^2.8.0"

[tool.poetry.dev-dependencies]
pytest-cov = "^2.12.0"
Expand Down
185 changes: 184 additions & 1 deletion tests/test_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,174 @@
from xstate.algorithm import is_parallel_state
"""Tests for algorithms

These tests use either machines coded as python `dict`
or accept strings representing xstate javascript/typescript which are
then converted to a python `dict` by the module `js2py`

The following tests exist
* test_is_parallel_state - returns the column headers of the file
* test_is_not_parallel_state - the main function of the script
"""

import pytest
from .utils_for_tests import pytest_func_docstring_summary


from xstate.algorithm import is_parallel_state, to_state_path, get_configuration
from xstate.machine import Machine


class TestAlgorithms:

test_machine = Machine(
""" {
id: 'a',
initial: 'b1',
states: {
b1: {
id: 'b1',
type: 'parallel',
states: {
c1: {
id: 'c1',
initial: 'd1',
states: {
d1: { id: 'd1' },
d2: {
id: 'd2',
initial: 'e1',
states: {
e1: { id: 'e1' },
e2: { id: 'e2' }
}
}
}
},
c2: { id: 'c2' },
c3: {
id: 'c3',
initial: 'd3',
states: {
d3: { id: 'd3' },
d4: {
id: 'd4',
initial: 'e3',
states: {
e3: { id: 'e3' },
e4: { id: 'e4' }
}
}
}
}
}
},
b2: {
id: 'b2',
initial: 'c4',
states: {
c4: { id: 'c4' }
}
},
b3: {
id: 'b3',
initial: 'c5',
states: {
c5: { id: 'c5' },
c6: {
id: 'c6',
type: 'parallel',
states: {
d5: { id: 'd5' },
d6: { id: 'd6' },
d7: { id: 'd7' }
}
}
}
}
}
}
"""
)

def test_algorithim_get_configuration(self, request):
"""1 - getConfiguration

ref: https://github.com/statelyai/xstate/blob/main/packages/core/test/algorithm.test.ts
"""
prev_nodes = self.test_machine.root.get_state_nodes(
# TODO: Should this be a config snippet `StateNode.get_state_nodes` does not decode dict
""" {
b1: {
c1: 'd1',
c2: {},
c3: 'd3'
}
}
"""
)
nodes = [self.test_machine.root.get_state_node_by_id(id) for id in ["c1", "d4"]]

c = get_configuration(prev_nodes, nodes)

assert sorted([sn.id for sn in c]) == [
"a",
"b1",
"c1",
"c2",
"c3",
"d1",
"d4",
"e3",
], pytest_func_docstring_summary(request)


def test_machine_config_translate():

xstate_js_config = """{
id: 'fan',
initial: 'off',
states: {
off: {
on: {
POWER:'on.hist',
H_POWER:'on.H',
SWITCH:'on.first'
}

},
on: {
initial: 'first',
states: {
first: {
on: {
SWITCH:'second'
}
},
second: {
on: {
SWITCH: 'third'
}
},
third: {},
H: {
type: 'history'
},
hist: {
type: 'history',
history:'shallow'
},
}
}
}
}
"""
# xstate_python_config=machine_config_translate(xstate_js_config)
# assert isinstance(xstate_python_config,dict)
try:
machine = Machine(xstate_js_config)
except Exception as e:
assert False, f"Machine config is not valid, Exception:{e}"


def test_is_parallel_state():
machine = Machine(
{"id": "test", "initial": "foo", "states": {"foo": {"type": "parallel"}}}
Expand All @@ -20,3 +187,19 @@ def test_is_not_parallel_state():
foo_state_node = machine._get_by_id("test.foo")

assert is_parallel_state(foo_state_node) is False


class TestStatePaths:
def test__to_state_path(self, request):
"""should have valid results for converstion to state paths list"""
assert to_state_path("one.two.three") == ["one", "two", "three"]
assert to_state_path("one/two/three", delimiter="/") == ["one", "two", "three"]
assert to_state_path(["one", "two", "three"]) == ["one", "two", "three"]
try:
state_id = {"values": ["one", "two", "three"]}
assert to_state_path(state_id) == ["one", "two", "three"]
except Exception as e:
assert (
e.args[0]
== "{'values': ['one', 'two', 'three']} is not a valid state path"
)
Loading