Gustaf-C / anki-chinese-support-3

Anki add-on providing support for Chinese study
https://ankiweb.net/shared/info/1752008591
GNU General Public License v3.0
26 stars 7 forks source link

Test with SaveNote is failed in commit 9cb0c26 #23

Closed BorisNA closed 8 months ago

BorisNA commented 8 months ago

Describe the bug After the commit 9cb0c26 test with SaveNote is failed

To Reproduce

  1. Run tests (with python 3.9)

Expected behavior Tests are Ok (as in the previous commit)

Additional context

ests/test_util.py::SaveNote::test_save_note FAILED                                                           [100%]

===================================================== FAILURES ======================================================
______________________________________________ SaveNote.test_save_note ______________________________________________

self = <tests.test_util.SaveNote testMethod=test_save_note>

    def test_save_note(self):
        class Note(dict):
            flush = Mock()

        note = Note()
        note.update({'hanzi': '我', 'pinyin': ''})
        copy = {'hanzi': '我', 'pinyin': 'wǒ'}
        self.assertEqual(save_note(note, copy), 1)
        self.assertEqual(note['pinyin'], 'wǒ')
>       note.flush.assert_called_once()

tests/test_util.py:123: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Mock id='140391872890192'>

    def assert_called_once(self):
        """assert that the mock was called only once.
        """
        if not self.call_count == 1:
            msg = ("Expected '%s' to have been called once. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
>           raise AssertionError(msg)
E           AssertionError: Expected 'mock' to have been called once. Called 0 times.

../../.pyenv/versions/3.9.18/lib/python3.9/unittest/mock.py:886: AssertionError
BorisNA commented 8 months ago

P.S. I also propose to switch Python in tests back to 3.9 (from 3.11) to match Anki's target. It could be important to Windows users, since 3.9 is bundled there

It is rather easy with pyenv + pyenv-virtual

Gustaf-C commented 8 months ago

Thanks, that's what I get for thinking such a small change can't possibly require the test be be ran...

Good catch with the python version, could cause problems.

Fixed in c32da96