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

Issue with Snapshots and Asian Characters #196

Closed
tehmufifnman opened this issue Apr 19, 2020 · 3 comments · Fixed by #198
Closed

Issue with Snapshots and Asian Characters #196

tehmufifnman opened this issue Apr 19, 2020 · 3 comments · Fixed by #198
Labels

Comments

@tehmufifnman
Copy link

tehmufifnman commented Apr 19, 2020

Describe the bug
I just started getting an error with Syrupy today when adding a new integration test for an API endpoint I am working on. I use Syrupy to diff the json returned vs a snapshot. When updating the snapshot (since it doesn't exist yet) I get an error that seems to be related to the presence of asian characters.

snapshot = SnapshotAssertion(name='snapshot', num_executions=1)

    def test_get_mythic_raid_leaderboard(snapshot):
        client = WarcraftClient(os.getenv("CLIENT_ID"), os.getenv("CLIENT_SECRET"))
        response = client.get_mythic_raid_leaderboard("uldir", "alliance")
>       assert response == snapshot

src\tests\integration\test_warcraft_client.py:296:

.venv\lib\site-packages\syrupy\assertion.py:123: in __eq__
    return self._assert(other)
.venv\lib\site-packages\syrupy\assertion.py:138: in _assert
    self.extension.write_snapshot(
.venv\lib\site-packages\syrupy\extensions\base.py:146: in write_snapshot
    self._write_snapshot_fossil(snapshot_fossil=snapshot_fossil)
.venv\lib\site-packages\syrupy\extensions\amber.py:317: in _write_snapshot_fossil
    DataSerializer.write_file(snapshot_fossil_to_update)
.venv\lib\site-packages\syrupy\extensions\amber.py:46: in write_file
    f.write(f"{cls._indent}{data_line}")

self = <encodings.cp1252.IncrementalEncoder object at 0x00000219EF7B9C10>, input = "          'name': '阿尔法',\n", final = False

    def encode(self, input, final=False):
>       return codecs.charmap_encode(input,self.errors,encoding_table)[0]
E       UnicodeEncodeError: 'charmap' codec can't encode characters in position 19-21: character maps to <undefined>

..\..\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py:19: UnicodeEncodeError

To Reproduce
Steps to reproduce the behavior:

  1. Setup a "test" of an API that returns this JSON (https://gist.github.com/tehmufifnman/856ddd77aab073b9687aada15f4e8a6b)
def test_get_some_data(snapshot):
    client = SomeClient()
    response = client.get_some_data()
    assert response == snapshot
  1. Run command 'pytest --snapshot-update'
  2. See error

Expected behavior
I expect it to save a new initial snapshot.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • Python Version: 3.8.2
@iamogbz
Copy link
Collaborator

iamogbz commented Apr 19, 2020

@tehmufifnman thanks for raising the issue, might be limited to windows which I don't have access to test with atm. However potential fix in the works here #198, you can test it out by installing the PR version of syrupy and and reporting back with results.

pip install -i https://test.pypi.org/simple/ syrupy==2020.4.19.43747420734

@tehmufifnman
Copy link
Author

Thanks @iamogbz ! This did indeed fix my issue, with one caveat. Since my original snapshot was written with the old encoding, it errored when trying to read it (even with --update-snapshot). Once I deleted the old ambr file and let it create a brand new one, it worked across the board.

@syrupy-bot
Copy link
Contributor

🎉 This issue has been resolved in version 0.4.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants