def test__scan_header(self):
        # This also tests the module scan_header

        # __init__ scans the header for some files, so to debug this it may be
        # useful to comment that section temporarily

        # Here we test if the errors are raised

        path = "no-time..asc"

        with open(path, "wt") as test_file:
            test_file.write("# column format: 1:data")

        with self.assertRaises(RuntimeError):
            cs.OneScalar(path)
        os.remove(path)

        path = "no-data..asc"

        with open(path, "wt") as test_file:
            test_file.write("# column format: 1:time")

        with self.assertRaises(RuntimeError):
            cs.OneScalar(path)

        os.remove(path)
    def test_OneScalar_magic_methods(self):

        path = "tests/tov/output-0000/static_tov/vel[0].maximum.asc"
        asc = cs.OneScalar(path)

        self.assertIn("vel[0]", asc)

        self.assertCountEqual(asc.keys(), ["vel[0]"])
    def test_load(self):

        # no reduction, scalar, one file per group
        path = "tests/tov/output-0000/static_tov/carpet-timing..asc"
        asc_carp = cs.OneScalar(path)
        t, y = np.loadtxt(path, ndmin=2, unpack=True, usecols=(8, 13))

        self.assertEqual(
            asc_carp.load("current_physical_time_per_hour"),
            ts.TimeSeries(t, y),
        )

        # Test __getitem__
        self.assertEqual(asc_carp["current_physical_time_per_hour"],
                         ts.TimeSeries(t, y))

        # Value not existing
        with self.assertRaises(KeyError):
            asc_carp.load("bubu")

        # Test scanning header
        path = "tests/tov/output-0000/static_tov/vel[0].maximum.asc"
        asc = cs.OneScalar(path)
        _ = asc.load("vel[0]")
    def test_OneScalar(self):

        # Filename not recogonized
        with self.assertRaises(RuntimeError):
            cs.OneScalar("123.h5")

        # Reduction not recogonized
        with self.assertRaises(RuntimeError):
            cs.OneScalar("hydrobase-press.bubu.asc")

        # maximum, vector, one file per variable
        path = "tests/tov/output-0000/static_tov/vel[0].maximum.asc"
        asc = cs.OneScalar(path)

        self.assertFalse(asc._is_one_file_per_group)
        self.assertFalse(asc._was_header_scanned)
        self.assertEqual(asc.reduction_type, "maximum")
        self.assertDictEqual(asc._vars_columns, {"vel[0]": None})

        # no reduction, scalar, one file per group
        path = "tests/tov/output-0000/static_tov/carpet-timing..asc"
        asc_carp = cs.OneScalar(path)

        self.assertTrue(asc_carp._is_one_file_per_group)
        self.assertTrue(asc_carp._was_header_scanned)
        self.assertIn("current_physical_time_per_hour", asc_carp._vars_columns)
        self.assertEqual(
            asc_carp._vars_columns["current_physical_time_per_hour"], 13)
        self.assertIn("time_total", asc_carp._vars_columns)
        self.assertEqual(asc_carp._vars_columns["time_total"], 14)
        self.assertIs(asc_carp.reduction_type, "scalar")

        # Compressed, scalar, one file per group
        path = "tests/tov/output-0000/static_tov/hydrobase-eps.minimum.asc.gz"
        asc_gz = cs.OneScalar(path)

        self.assertTrue(asc_gz._is_one_file_per_group)
        self.assertTrue(asc_gz._was_header_scanned)
        self.assertEqual(asc_gz.reduction_type, "minimum")
        self.assertEqual(asc_gz._compression_method, "gz")
        self.assertDictEqual(asc_gz._vars_columns, {"eps": 2})

        # Compressed, scalar, one file per group
        path = "tests/tov/output-0000/static_tov/hydrobase-eps.minimum.asc.bz2"
        asc_bz = cs.OneScalar(path)
        self.assertEqual(asc_bz._compression_method, "bz2")
        self.assertDictEqual(asc_bz._vars_columns, {"eps": 2})