Skip to content

Commit

Permalink
Test write to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Sep 13, 2024
1 parent 23857fa commit e75796f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
30 changes: 30 additions & 0 deletions src/jsonyx/test/test_dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (C) 2024 Nice Zombies
"""JSON dump tests."""
from __future__ import annotations

__all__: list[str] = []

from contextlib import redirect_stdout
from io import StringIO
from typing import TYPE_CHECKING

# pylint: disable-next=W0611
from jsonyx.test import get_json # type: ignore # noqa: F401

if TYPE_CHECKING:
from types import ModuleType


def test_file(json: ModuleType) -> None:
"""Test write to file."""
io: StringIO = StringIO()
json.dump(0, io, end="")
assert io.getvalue() == "0"


def test_stdout(json: ModuleType) -> None:
"""Test write to stdout."""
io: StringIO = StringIO()
with redirect_stdout(io):
json.dump(0, end="")
assert io.getvalue() == "0"
7 changes: 0 additions & 7 deletions src/jsonyx/test/test_jsonyx.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ def test_format_syntax_error(
)


def test_dump(json: ModuleType) -> None:
"""Test JSON dump."""
io: StringIO = StringIO()
json.dump(0, io, end="")
assert io.getvalue() == "0"


def test_load(json: ModuleType) -> None:
"""Test JSON load."""
assert json.load(StringIO("0")) == 0
Expand Down

0 comments on commit e75796f

Please sign in to comment.