Coverage for tests/test_tap.py: 56%

30 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-16 02:49 -0700

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/>. 

21 

22import os 

23import shutil 

24import tempfile 

25import unittest 

26from collections.abc import MutableMapping 

27from typing import Any 

28 

29import sqlalchemy 

30import yaml 

31 

32from felis.datamodel import Schema 

33from felis.tap import Tap11Base, TapLoadingVisitor, init_tables 

34 

35TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

36TEST_YAML = os.path.join(TESTDIR, "data", "test.yml") 

37 

38 

39class VisitorTestCase(unittest.TestCase): 

40 """Tests for TapLoadingVisitor class.""" 

41 

42 schema_obj: MutableMapping[str, Any] = {} 

43 

44 def setUp(self) -> None: 

45 """Load data from test file.""" 

46 with open(TEST_YAML) as test_yaml: 

47 yaml_data = yaml.load(test_yaml, Loader=yaml.SafeLoader) 

48 self.schema_obj = Schema.model_validate(yaml_data) 

49 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR) 

50 

51 def tearDown(self) -> None: 

52 shutil.rmtree(self.tmpdir, ignore_errors=True) 

53 

54 def test_tap(self) -> None: 

55 """Test for creating tap schema.""" 

56 url = f"sqlite:///{self.tmpdir}/tap.sqlite3" 

57 engine = sqlalchemy.create_engine(url) 

58 tap_tables = init_tables() 

59 Tap11Base.metadata.create_all(engine) 

60 

61 # This repeats logic from cli.py. 

62 tap_visitor = TapLoadingVisitor(engine, tap_tables=tap_tables) 

63 tap_visitor.visit_schema(self.schema_obj) 

64 

65 

66if __name__ == "__main__": 66 ↛ 67line 66 didn't jump to line 67, because the condition on line 66 was never true

67 unittest.main()