import pytest

from inline_snapshot import Is
from inline_snapshot import snapshot
from inline_snapshot.testing._example import Example


@pytest.mark.parametrize("storage", ["uuid", "hash"])
def test_generic(storage):
    Example(f"""\
from inline_snapshot import external

def test_a():
    string="testa".upper()
    assert string==external("{storage}:")
""").run_pytest(
        ["--inline-snapshot=report"],
        returncode=snapshot(1),
        error=Is(f"""\
>       assert string==external("{storage}:")
E       assert 'TESTA' == external("{storage}:")
E        +  where external("{storage}:") = external('{storage}:')
"""),
        outcomes={"failed": 1, "errors": 1},
        changed_files={".inline-snapshot/files_using_external.txt": """\
# this file is generated by inline-snapshot and requires no manual edits (https://15r10nk.github.io/inline-snapshot/latest/external/external/#cleaning-up-old-externals)
tests/test_something.py
"""},
    ).run_inline(
        ["--inline-snapshot=create"],
        changed_files=snapshot(
            {
                "uuid": {
                    "tests/__inline_snapshot__/test_something/test_a/cd613e30-d8f1-4adf-91b7-584a2265b1f5.txt": "TESTA",
                    "tests/test_something.py": """\
from inline_snapshot import external

def test_a():
    string="testa".upper()
    assert string==external("uuid:cd613e30-d8f1-4adf-91b7-584a2265b1f5.txt")
""",
                },
                "hash": {
                    ".inline-snapshot/external/8b95fa6246dc4446718de0b06cbf083677e4b1ec3bace1599d4daf84768f67ee.txt": "TESTA",
                    "tests/test_something.py": """\
from inline_snapshot import external

def test_a():
    string="testa".upper()
    assert string==external("hash:8b95fa6246dc*.txt")
""",
                },
            }
        )[storage],
    ).replace(
        "testa", "testb"
    ).run_pytest(
        ["--inline-snapshot=fix"],
        changed_files=snapshot(
            {
                "uuid": {
                    "tests/__inline_snapshot__/test_something/test_a/cd613e30-d8f1-4adf-91b7-584a2265b1f5.txt": "TESTB"
                },
                "hash": {
                    ".inline-snapshot/external/78e8a8fafad325dcf5ba036e127b88ed56131b8daaf6fcd925722bc3dccead72.txt": "TESTB",
                    "tests/test_something.py": """\
from inline_snapshot import external

def test_a():
    string="testb".upper()
    assert string==external("hash:78e8a8fafad3*.txt")
""",
                },
            }
        )[storage],
        report=snapshot(
            {
                "uuid": """\
+--------------- uuid:cd613e30-d8f1-4adf-91b7-584a2265b1f5.txt ----------------+
| @@ -1 +1 @@                                                                  |
|                                                                              |
| -TESTA                                                                       |
| +TESTB                                                                       |
+------------------------------------------------------------------------------+
These changes will be applied, because you used fix\
""",
                "hash": """\
-------------------------------- Fix snapshots ---------------------------------
+-------------------------- tests/test_something.py ---------------------------+
| @@ -2,4 +2,4 @@                                                              |
|                                                                              |
|                                                                              |
|  def test_a():                                                               |
|      string="testb".upper()                                                  |
| -    assert string==external("hash:8b95fa6246dc*.txt")                       |
| +    assert string==external("hash:78e8a8fafad3*.txt")                       |
+------------------------------------------------------------------------------+
+-------------- hash:8b95fa6246dc*.txt -> hash:78e8a8fafad3*.txt --------------+
| @@ -1 +1 @@                                                                  |
|                                                                              |
| -TESTA                                                                       |
| +TESTB                                                                       |
+------------------------------------------------------------------------------+
These changes will be applied, because you used fix\
""",
            }
        )[storage],
        returncode=1,
        outcomes={"passed": 1, "errors": 1},
    )
