<filename>tests/test_dat.py
import numpy as np

from pathlib import Path
from deepdiff import DeepDiff
from priwo import read_dat, write_dat
from tempfile import NamedTemporaryFile


fnames = [
    "test_fake_presto_radio.dat",
    "test_fake_presto_radio_breaks.dat",
    "test_fake_presto_xray.dat",
]

fdata = np.asarray(
    [
        0.0,
        1.0,
        2.0,
        3.0,
        4.0,
        5.0,
        6.0,
        7.0,
        8.0,
        9.0,
        10.0,
        11.0,
        12.0,
        13.0,
        14.0,
        15.0,
    ],
    dtype=np.float32,
)


def test_read_dat(datadir):

    """
    Test reading in a `*.dat` file.
    """

    for fname in fnames:
        data = read_dat(datadir.joinpath(fname))["data"]
        assert DeepDiff(fdata, data) == {}


def test_write_dat(datadir):

    """
    Test writing out a `*.dat` file.
    """

    for fname in fnames:
        with NamedTemporaryFile(suffix=".dat") as tfobj:
            write_dat(
                read_dat(datadir.joinpath(fname)),
                Path(tfobj.name),
            )
            data = read_dat(tfobj.name)["data"]
            assert DeepDiff(fdata, data) == {}

<filename>tests/test_dat.py
import numpy as np

from pathlib import Path
from deepdiff import DeepDiff
from priwo import read_dat, write_dat
from tempfile import NamedTemporaryFile


fnames = [
    "test_fake_presto_radio.dat",
    "test_fake_presto_radio_breaks.dat",
    "test_fake_presto_xray.dat",
]

fdata = np.asarray(
    [
        0.0,
        1.0,
        2.0,
        3.0,
        4.0,
        5.0,
        6.0,
        7.0,
        8.0,
        9.0,
        10.0,
        11.0,
        12.0,
        13.0,
        14.0,
        15.0,
    ],
    dtype=np.float32,
)


def test_read_dat(datadir):

    """
    Test reading in a `*.dat` file.
    """

    for fname in fnames:
        data = read_dat(datadir.joinpath(fname))["data"]
        assert DeepDiff(fdata, data) == {}


def test_write_dat(datadir):

    """
    Test writing out a `*.dat` file.
    """

    for fname in fnames:
        with NamedTemporaryFile(suffix=".dat") as tfobj:
            write_dat(
                read_dat(datadir.joinpath(fname)),
                Path(tfobj.name),
            )
            data = read_dat(tfobj.name)["data"]
            assert DeepDiff(fdata, data) == {}

Test reading in a `*.dat` file. Test writing out a `*.dat` file.