# Path: test/_common.py
# def print_test_result(expected, actual, error=None):
#     print(f"[expected]\n{expected}\n")
#     print(f"[actual]\n{actual}\n")
# 
#     if error:
#         print(error, file=sys.stderr)
# 
#     print("----------------------------------------")
# 
# Path: test/data.py
# TIME = datetime.datetime(2017, 1, 1, 0, 0, 0)
# INF = float("inf")
# NAN = float("nan")


import collections
import itertools
import pytest
import yaml
import pytablewriter as ptw
from io import StringIO
from textwrap import dedent
from tabledata import TableData
from ..._common import print_test_result
from ...data import float_tabledata, mix_tabledata, value_matrix


class Test_YamlTableWriter_write_new_line:
    def test_normal(self, capsys):
        writer = table_writer_class()
        writer.write_null_line()

        out, _err = capsys.readouterr()

        assert out == "\n"


class Test_YamlTableWriter_write_table:
    @pytest.mark.parametrize(
        ["value", "expected"],
        [[data.tabledata, data.expected] for data in normal_test_data_list],
    )
    def test_normal(self, capsys, value, expected):
        writer = table_writer_class()
        writer.from_tabledata(value)
        writer.write_table()

        out, err = capsys.readouterr()
        print_test_result(expected=expected, actual=out, error=err)
        assert out == expected
        assert yaml.safe_load(StringIO(out))

        # margin setting must be ignored
        writer.margin = 1
        dumps_out = writer.dumps()

# Path: test/_common.py
# def print_test_result(expected, actual, error=None):
#     print(f"[expected]\n{expected}\n")
#     print(f"[actual]\n{actual}\n")
# 
#     if error:
#         print(error, file=sys.stderr)
# 
#     print("----------------------------------------")
# 
# Path: test/data.py
# TIME = datetime.datetime(2017, 1, 1, 0, 0, 0)
# INF = float("inf")
# NAN = float("nan")


# Path: test/writer/text/test_yaml_writer.py
import collections
import itertools
import pytest
import yaml
import pytablewriter as ptw
from io import StringIO
from textwrap import dedent
from tabledata import TableData
from ..._common import print_test_result
from ...data import float_tabledata, mix_tabledata, value_matrix



class Test_YamlTableWriter_write_new_line:
    def test_normal(self, capsys):
        writer = table_writer_class()
        writer.write_null_line()

        out, _err = capsys.readouterr()

        assert out == "\n"


class Test_YamlTableWriter_write_table:
    @pytest.mark.parametrize(
        ["value", "expected"],
        [[data.tabledata, data.expected] for data in normal_test_data_list],
    )
    def test_normal(self, capsys, value, expected):
        writer = table_writer_class()
        writer.from_tabledata(value)
        writer.write_table()

        out, err = capsys.readouterr()
        print_test_result(expected=expected, actual=out, error=err)
        assert out == expected
        assert yaml.safe_load(StringIO(out))

        # margin setting must be ignored
        writer.margin = 1
        dumps_out = writer.dumps()

        print_test_result(expected=out, actual=dumps_out)