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

tests/test_state.py:137: AssertionError #31

Closed
carlosal1015 opened this issue Jan 2, 2025 · 3 comments
Closed

tests/test_state.py:137: AssertionError #31

carlosal1015 opened this issue Jan 2, 2025 · 3 comments

Comments

@carlosal1015
Copy link

Hi, in the last version we have this error.

============================= test session starts ==============================
platform linux -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0 -- /build/python-trame-server/src/trame-server-3.2.4/test-env/bin/python
cachedir: .pytest_cache
rootdir: /build/python-trame-server/src/trame-server-3.2.4
configfile: pyproject.toml
collecting ... collected 6 items

tests/test_controller.py::test_define_later PASSED                       [ 16%]
tests/test_controller.py::test_trigger_name PASSED                       [ 33%]
tests/test_state.py::test_minimum_change_detection FAILED                [ 50%]
tests/test_translator.py::test_translation PASSED                        [ 66%]
tests/test_translator.py::test_prefix PASSED                             [ 83%]
tests/test_translator.py::test_prefix_and_translation PASSED             [100%]

=================================== FAILURES ===================================
________________________ test_minimum_change_detection _________________________

    def test_minimum_change_detection():
        """
         0 msg  : test_minimum_change_detection
         1 msg  : Before server ready
         2 push : {'a': 2}
         3 exec : 2
         4 msg  : After server ready
         5 msg  : (prev=2) After 2, 3, 3, 4, 4
         6 msg  : (prev=4) Before Flush
         7 push : {'a': 4}
         8 exec : 4
         9 msg  : (prev=4) After Flush
        10 msg  : Enter with a=4
        11 msg  : About to exit a=4
        12 msg  : (prev=4) After with state + same value
        13 msg  : Enter with a=4
        14 msg  : About to exit a=5
        15 push : {'a': 5}
        16 exec : 5
        17 msg  : (prev=5) After with state + 3,4,5
        18 msg  : Enter with a=5
        19 msg  : About to exit a=5
        20 msg  : (prev=5) After with state + 3,5,4,5
        21 msg  : Enter with a=5
        22 msg  : About to exit a=5
        23 push : {'b': 3, 'c': 2}
        24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2
        25 msg  : Enter with a=5
        26 msg  : About to exit a=1
        27 push : {'a': 1, 'b': 2, 'c': 3}
        28 exec : 1
        """
        server = FakeServer()
        server.add_event("test_minimum_change_detection")
        state = State(commit_fn=server._push_state)
    
        @state.change("a")
        def on_change_exec(a, **kwargs):
            server.add_event(type="exec", content=a)
    
        state.a = 1
        state.a = 1
        state.a = 2
        state.a = 2
    
        server.add_event("Before server ready")
        state.ready()
        server.add_event("After server ready")
    
        state.a = 2
        state.a = 3
        state.a = 3
        state.a = 4
        state.a = 4
    
        server.add_event("(prev=2) After 2, 3, 3, 4, 4")
    
        # Flush
        server.add_event("(prev=4) Before Flush")
        state.flush()
        server.add_event("(prev=4) After Flush")
    
        # This should be a NoOp
        with state:
            server.add_event(f"Enter with a={state.a}")
            state.a = 4
            server.add_event(f"About to exit a={state.a}")
    
        server.add_event("(prev=4) After with state + same value")
    
        with state:
            server.add_event(f"Enter with a={state.a}")
            state.a = 3
            state.a = 4
            state.a = 5
            server.add_event(f"About to exit a={state.a}")
    
        server.add_event("(prev=5) After with state + 3,4,5")
    
        # Even though it changed, finally it is the same value
        with state:
            server.add_event(f"Enter with a={state.a}")
            state.a = 3
            state.a = 5
            state.a = 4
            state.a = 5
            server.add_event(f"About to exit a={state.a}")
    
        server.add_event("(prev=5) After with state + 3,5,4,5")
    
        # Use update to set {a: 1, b: 2, c: 3}
        with state:
            server.add_event(f"Enter with a={state.a}")
            state.update(dict(a=1, b=2, c=3))
            state.update(dict(a=5, b=3, c=2))
            server.add_event(f"About to exit a={state.a}")
    
        server.add_event("(prev=5) After with state + a:1,5 b:2,3 c:3,2")
    
        # Use update to set {a: 1, b: 2, c: 3}
        with state:
            server.add_event(f"Enter with a={state.a}")
            state.update(dict(a=1, b=2, c=3))
            server.add_event(f"About to exit a={state.a}")
    
        # Validate event
        result = str(server)
        expected = str(test_minimum_change_detection.__doc__)
    
        # Grab new scenario output
        # print(result)
    
>       assert expected.strip() == result.strip()
E       assert "0 msg  : test_minimum_change_detection\n 1 msg  : Before server ready\n 2 push : {'a': 2}\n 3 exec : 2\n 4 msg  : After server ready\n 5 msg  : (prev=2) After 2, 3, 3, 4, 4\n 6 msg  : (prev=4) Before Flush\n 7 push : {'a': 4}\n 8 exec : 4\n 9 msg  : (prev=4) After Flush\n10 msg  : Enter with a=4\n11 msg  : About to exit a=4\n12 msg  : (prev=4) After with state + same value\n13 msg  : Enter with a=4\n14 msg  : About to exit a=5\n15 push : {'a': 5}\n16 exec : 5\n17 msg  : (prev=5) After with state + 3,4,5\n18 msg  : Enter with a=5\n19 msg  : About to exit a=5\n20 msg  : (prev=5) After with state + 3,5,4,5\n21 msg  : Enter with a=5\n22 msg  : About to exit a=5\n23 push : {'b': 3, 'c': 2}\n24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2\n25 msg  : Enter with a=5\n26 msg  : About to exit a=1\n27 push : {'a': 1, 'b': 2, 'c': 3}\n28 exec : 1" == "0 msg  : test_minimum_change_detection\n     1 msg  : Before server ready\n     2 push : {'a': 2}\n     3 exec : 2\n     4 msg  : After server ready\n     5 msg  : (prev=2) After 2, 3, 3, 4, 4\n     6 msg  : (prev=4) Before Flush\n     7 push : {'a': 4}\n     8 exec : 4\n     9 msg  : (prev=4) After Flush\n    10 msg  : Enter with a=4\n    11 msg  : About to exit a=4\n    12 msg  : (prev=4) After with state + same value\n    13 msg  : Enter with a=4\n    14 msg  : About to exit a=5\n    15 push : {'a': 5}\n    16 exec : 5\n    17 msg  : (prev=5) After with state + 3,4,5\n    18 msg  : Enter with a=5\n    19 msg  : About to exit a=5\n    20 msg  : (prev=5) After with state + 3,5,4,5\n    21 msg  : Enter with a=5\n    22 msg  : About to exit a=5\n    23 push : {'b': 3, 'c': 2}\n    24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2\n    25 msg  : Enter with a=5\n    26 msg  : About to exit a=1\n    27 push : {'a': 1, 'b': 2, 'c': 3}\n    28 exec : 1"
E         
E           0 msg  : test_minimum_change_detection
E         -      1 msg  : Before server ready
E         ? ----
E         +  1 msg  : Before server ready
E         -      2 push : {'a': 2}
E         ? ----
E         +  2 push : {'a': 2}
E         -      3 exec : 2
E         ? ----
E         +  3 exec : 2
E         -      4 msg  : After server ready
E         ? ----
E         +  4 msg  : After server ready
E         -      5 msg  : (prev=2) After 2, 3, 3, 4, 4
E         ? ----
E         +  5 msg  : (prev=2) After 2, 3, 3, 4, 4
E         -      6 msg  : (prev=4) Before Flush
E         ? ----
E         +  6 msg  : (prev=4) Before Flush
E         -      7 push : {'a': 4}
E         ? ----
E         +  7 push : {'a': 4}
E         -      8 exec : 4
E         ? ----
E         +  8 exec : 4
E         -      9 msg  : (prev=4) After Flush
E         ? ----
E         +  9 msg  : (prev=4) After Flush
E         -     10 msg  : Enter with a=4
E         ? ----
E         + 10 msg  : Enter with a=4
E         -     11 msg  : About to exit a=4
E         ? ----
E         + 11 msg  : About to exit a=4
E         -     12 msg  : (prev=4) After with state + same value
E         ? ----
E         + 12 msg  : (prev=4) After with state + same value
E         -     13 msg  : Enter with a=4
E         ? ----
E         + 13 msg  : Enter with a=4
E         -     14 msg  : About to exit a=5
E         ? ----
E         + 14 msg  : About to exit a=5
E         -     15 push : {'a': 5}
E         ? ----
E         + 15 push : {'a': 5}
E         -     16 exec : 5
E         ? ----
E         + 16 exec : 5
E         -     17 msg  : (prev=5) After with state + 3,4,5
E         ? ----
E         + 17 msg  : (prev=5) After with state + 3,4,5
E         -     18 msg  : Enter with a=5
E         ? ----
E         + 18 msg  : Enter with a=5
E         -     19 msg  : About to exit a=5
E         ? ----
E         + 19 msg  : About to exit a=5
E         -     20 msg  : (prev=5) After with state + 3,5,4,5
E         ? ----
E         + 20 msg  : (prev=5) After with state + 3,5,4,5
E         -     21 msg  : Enter with a=5
E         ? ----
E         + 21 msg  : Enter with a=5
E         -     22 msg  : About to exit a=5
E         ? ----
E         + 22 msg  : About to exit a=5
E         -     23 push : {'b': 3, 'c': 2}
E         ? ----
E         + 23 push : {'b': 3, 'c': 2}
E         -     24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2
E         ? ----
E         + 24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2
E         -     25 msg  : Enter with a=5
E         ? ----
E         + 25 msg  : Enter with a=5
E         -     26 msg  : About to exit a=1
E         ? ----
E         + 26 msg  : About to exit a=1
E         -     27 push : {'a': 1, 'b': 2, 'c': 3}
E         ? ----
E         + 27 push : {'a': 1, 'b': 2, 'c': 3}
E         -     28 exec : 1
E         ? ----
E         + 28 exec : 1

tests/test_state.py:137: AssertionError
=========================== short test summary info ============================
FAILED tests/test_state.py::test_minimum_change_detection - assert "0 msg  : test_minimum_change_detection\n 1 msg  : Before server ready\n 2 push : {'a': 2}\n 3 exec : 2\n 4 msg  : After server ready\n 5 msg  : (prev=2) After 2, 3, 3, 4, 4\n 6 msg  : (prev=4) Before Flush\n 7 push : {'a': 4}\n 8 exec : 4\n 9 msg  : (prev=4) After Flush\n10 msg  : Enter with a=4\n11 msg  : About to exit a=4\n12 msg  : (prev=4) After with state + same value\n13 msg  : Enter with a=4\n14 msg  : About to exit a=5\n15 push : {'a': 5}\n16 exec : 5\n17 msg  : (prev=5) After with state + 3,4,5\n18 msg  : Enter with a=5\n19 msg  : About to exit a=5\n20 msg  : (prev=5) After with state + 3,5,4,5\n21 msg  : Enter with a=5\n22 msg  : About to exit a=5\n23 push : {'b': 3, 'c': 2}\n24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2\n25 msg  : Enter with a=5\n26 msg  : About to exit a=1\n27 push : {'a': 1, 'b': 2, 'c': 3}\n28 exec : 1" == "0 msg  : test_minimum_change_detection\n     1 msg  : Before server ready\n     2 push : {'a': 2}\n     3 exec : 2\n     4 msg  : After server ready\n     5 msg  : (prev=2) After 2, 3, 3, 4, 4\n     6 msg  : (prev=4) Before Flush\n     7 push : {'a': 4}\n     8 exec : 4\n     9 msg  : (prev=4) After Flush\n    10 msg  : Enter with a=4\n    11 msg  : About to exit a=4\n    12 msg  : (prev=4) After with state + same value\n    13 msg  : Enter with a=4\n    14 msg  : About to exit a=5\n    15 push : {'a': 5}\n    16 exec : 5\n    17 msg  : (prev=5) After with state + 3,4,5\n    18 msg  : Enter with a=5\n    19 msg  : About to exit a=5\n    20 msg  : (prev=5) After with state + 3,5,4,5\n    21 msg  : Enter with a=5\n    22 msg  : About to exit a=5\n    23 push : {'b': 3, 'c': 2}\n    24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2\n    25 msg  : Enter with a=5\n    26 msg  : About to exit a=1\n    27 push : {'a': 1, 'b': 2, 'c': 3}\n    28 exec : 1"
  
    0 msg  : test_minimum_change_detection
  -      1 msg  : Before server ready
  ? ----
  +  1 msg  : Before server ready
  -      2 push : {'a': 2}
  ? ----
  +  2 push : {'a': 2}
  -      3 exec : 2
  ? ----
  +  3 exec : 2
  -      4 msg  : After server ready
  ? ----
  +  4 msg  : After server ready
  -      5 msg  : (prev=2) After 2, 3, 3, 4, 4
  ? ----
  +  5 msg  : (prev=2) After 2, 3, 3, 4, 4
  -      6 msg  : (prev=4) Before Flush
  ? ----
  +  6 msg  : (prev=4) Before Flush
  -      7 push : {'a': 4}
  ? ----
  +  7 push : {'a': 4}
  -      8 exec : 4
  ? ----
  +  8 exec : 4
  -      9 msg  : (prev=4) After Flush
  ? ----
  +  9 msg  : (prev=4) After Flush
  -     10 msg  : Enter with a=4
  ? ----
  + 10 msg  : Enter with a=4
  -     11 msg  : About to exit a=4
  ? ----
  + 11 msg  : About to exit a=4
  -     12 msg  : (prev=4) After with state + same value
  ? ----
  + 12 msg  : (prev=4) After with state + same value
  -     13 msg  : Enter with a=4
  ? ----
  + 13 msg  : Enter with a=4
  -     14 msg  : About to exit a=5
  ? ----
  + 14 msg  : About to exit a=5
  -     15 push : {'a': 5}
  ? ----
  + 15 push : {'a': 5}
  -     16 exec : 5
  ? ----
  + 16 exec : 5
  -     17 msg  : (prev=5) After with state + 3,4,5
  ? ----
  + 17 msg  : (prev=5) After with state + 3,4,5
  -     18 msg  : Enter with a=5
  ? ----
  + 18 msg  : Enter with a=5
  -     19 msg  : About to exit a=5
  ? ----
  + 19 msg  : About to exit a=5
  -     20 msg  : (prev=5) After with state + 3,5,4,5
  ? ----
  + 20 msg  : (prev=5) After with state + 3,5,4,5
  -     21 msg  : Enter with a=5
  ? ----
  + 21 msg  : Enter with a=5
  -     22 msg  : About to exit a=5
  ? ----
  + 22 msg  : About to exit a=5
  -     23 push : {'b': 3, 'c': 2}
  ? ----
  + 23 push : {'b': 3, 'c': 2}
  -     24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2
  ? ----
  + 24 msg  : (prev=5) After with state + a:1,5 b:2,3 c:3,2
  -     25 msg  : Enter with a=5
  ? ----
  + 25 msg  : Enter with a=5
  -     26 msg  : About to exit a=1
  ? ----
  + 26 msg  : About to exit a=1
  -     27 push : {'a': 1, 'b': 2, 'c': 3}
  ? ----
  + 27 push : {'a': 1, 'b': 2, 'c': 3}
  -     28 exec : 1
  ? ----
  + 28 exec : 1
========================= 1 failed, 5 passed in 0.03s ==========================
@jourdain
Copy link
Collaborator

jourdain commented Jan 2, 2025

The CI and my local machine seems to be ok with that test. Not sure what could be happening here.

The error seems to be related to indentation. Could you confirm that is indeed the issue?

Can you check if the following code edit would fix the failure on your end?

# ...

# Validate event
result = [line.strip() for line in str(server).split("\n")]
expected = [line.strip() for line in str(test_minimum_change_detection.__doc__).split("\n")]

# Grab new scenario output
# print(result)

assert expected == result

@carlosal1015
Copy link
Author

carlosal1015 commented Jan 2, 2025

Can you check if the following code edit would fix the failure on your end?

# ...

# Validate event
result = [line.strip() for line in str(server).split("\n")]
expected = [line.strip() for line in str(test_minimum_change_detection.__doc__).split("\n")]

# Grab new scenario output
# print(result)

assert expected == result

Now is fixed when I applied bf20291072a5f1750e1cd885f494d48e55d8c10e commit.

==> Starting check()...
============================= test session starts ==============================
platform linux -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0
rootdir: /build/python-trame-server/src/trame-server-3.2.4
configfile: pyproject.toml
collected 6 items

tests/test_controller.py ..                                              [ 33%]
tests/test_state.py .                                                    [ 50%]
tests/test_translator.py ...                                             [100%]

============================== 6 passed in 0.02s ===============================
==> Entering fakeroot environment...
==> Starting package()...
==> Tidying install...
  -> Removing libtool files...
  -> Purging unwanted files...
  -> Removing static library files...
  -> Stripping unneeded symbols from binaries and libraries...
  -> Compressing man and info pages...
==> Checking for packaging issues...
==> Creating package "python-trame-server"...
  -> Generating .PKGINFO file...
  -> Generating .BUILDINFO file...
  -> Generating .MTREE file...
  -> Compressing package...
==> Leaving fakeroot environment.
==> Finished making: python-trame-server 3.2.4-1 (Thu Jan  2 17:58:55 2025)

https://github.com/arch4edu/cactus/actions/runs/12576529745/job/35080943638

@jourdain
Copy link
Collaborator

jourdain commented Jan 2, 2025

thx for your feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants