test_embedding.AssertTest fails #530

Open
opened 2024-08-30 13:29:04 +08:00 by sb10q · 1 comment
Owner
======================================================================
FAIL: test_assert (test_embedding.AssertTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sb/artiq/artiq/test/coredevice/test_embedding.py", line 551, in test_assert
    check_fail(lambda: exp.check(False), "AssertionError")
  File "/home/sb/artiq/artiq/test/coredevice/test_embedding.py", line 548, in check_fail
    self.assertEqual(str(ctx.exception), msg)
AssertionError: '' != 'AssertionError'
+ AssertionError

``` ====================================================================== FAIL: test_assert (test_embedding.AssertTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/sb/artiq/artiq/test/coredevice/test_embedding.py", line 551, in test_assert check_fail(lambda: exp.check(False), "AssertionError") File "/home/sb/artiq/artiq/test/coredevice/test_embedding.py", line 548, in check_fail self.assertEqual(str(ctx.exception), msg) AssertionError: '' != 'AssertionError' + AssertionError ```
Collaborator

The str() of an AssertionError if raised by assert False without an associated message is "" in Python. NAC3 defines it that way too. Perhaps the expected value itself is wrong?

Relevant test case source for reference:

@nac3
class _Assert(EnvExperiment):
    core: KernelInvariant[Core]

    def build(self):
        self.setattr_device("core")

    @kernel
    def check(self, value: bool):
        assert value

    @kernel
    def check_msg(self, value: bool):
        assert value, "foo"


class AssertTest(ExperimentCase):
    @unittest.skip("NAC3TODO https://git.m-labs.hk/M-Labs/nac3/issues/530")
    def test_assert(self):
        exp = self.create(_Assert)

        def check_fail(fn, msg):
            with self.assertRaises(AssertionError) as ctx:
                fn()
            self.assertEqual(str(ctx.exception), msg)

        exp.check(True)
        check_fail(lambda: exp.check(False), "AssertionError") # Line 551
        exp.check_msg(True)
        check_fail(lambda: exp.check_msg(False), "foo")
The `str()` of an `AssertionError` if raised by `assert False` without an associated message is `""` in Python. NAC3 defines it that way too. Perhaps the expected value itself is wrong? Relevant test case source for reference: ```python @nac3 class _Assert(EnvExperiment): core: KernelInvariant[Core] def build(self): self.setattr_device("core") @kernel def check(self, value: bool): assert value @kernel def check_msg(self, value: bool): assert value, "foo" class AssertTest(ExperimentCase): @unittest.skip("NAC3TODO https://git.m-labs.hk/M-Labs/nac3/issues/530") def test_assert(self): exp = self.create(_Assert) def check_fail(fn, msg): with self.assertRaises(AssertionError) as ctx: fn() self.assertEqual(str(ctx.exception), msg) exp.check(True) check_fail(lambda: exp.check(False), "AssertionError") # Line 551 exp.check_msg(True) check_fail(lambda: exp.check_msg(False), "foo") ```
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#530
No description provided.