turbomam/examples-first-cookiecutter

Python instantiation test should consider Collections only

Closed this issue · 1 comments

and take them form the valid examples dir

sample code from generated repo:

"""Data test."""
import os
import glob
import unittest

from linkml_runtime.loaders import yaml_loader
from my_awesome_schema.datamodel.my_awesome_schema import PersonCollection

ROOT = os.path.join(os.path.dirname(__file__), '..')
DATA_DIR = os.path.join(ROOT, "src", "data", "examples", "valid")

EXAMPLE_FILES = glob.glob(os.path.join(DATA_DIR, '*.yaml'))


class TestData(unittest.TestCase):
    """Test data and datamodel."""

    def test_data(self):
        """Date test."""
        acceptable_prefix = f"{DATA_DIR}/{PersonCollection.class_name}"
        print()
        for path in EXAMPLE_FILES:
            if path.startswith(acceptable_prefix):
                obj = yaml_loader.load(path, target_class=PersonCollection)
                assert obj
            else:
                print(f"{path} does not match {acceptable_prefix} so will not be tested")