Coverage for tests/test_tap.py: 47%
35 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-14 02:21 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-14 02:21 -0800
1# This file is part of felis.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import os
23import shutil
24import tempfile
25import unittest
26from collections.abc import MutableMapping
27from typing import Any
29import sqlalchemy
30import yaml
32from felis import DEFAULT_FRAME
33from felis.cli import _normalize
34from felis.tap import Tap11Base, TapLoadingVisitor, init_tables
36TESTDIR = os.path.abspath(os.path.dirname(__file__))
37TEST_YAML = os.path.join(TESTDIR, "data", "test.yml")
40class VisitorTestCase(unittest.TestCase):
41 """Tests for TapLoadingVisitor class."""
43 schema_obj: MutableMapping[str, Any] = {}
45 def setUp(self) -> None:
46 """Load data from test file."""
47 with open(TEST_YAML) as test_yaml:
48 self.schema_obj = yaml.load(test_yaml, Loader=yaml.SafeLoader)
49 self.schema_obj.update(DEFAULT_FRAME)
50 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR)
52 def tearDown(self) -> None:
53 shutil.rmtree(self.tmpdir, ignore_errors=True)
55 def test_tap(self) -> None:
56 """Test for creating tap schema"""
58 url = f"sqlite:///{self.tmpdir}/tap.sqlite3"
59 engine = sqlalchemy.create_engine(url)
60 tap_tables = init_tables()
61 Tap11Base.metadata.create_all(engine)
63 # This repeats logic from cli.py.
64 normalized = _normalize(self.schema_obj)
65 if isinstance(normalized["@graph"], dict):
66 normalized["@graph"] = [normalized["@graph"]]
67 for schema in normalized["@graph"]:
68 tap_visitor = TapLoadingVisitor(engine, tap_tables=tap_tables)
69 tap_visitor.visit_schema(schema)
72if __name__ == "__main__": 72 ↛ 73line 72 didn't jump to line 73, because the condition on line 72 was never true
73 unittest.main()