You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there,
I recently cloned the example project from GitHub that uses Cookiecutter templates for generating the project structure. I encountered an issue with the test_data.py file when trying to validate my example YAML data.
In "Creating a new project-->Step 1: Generate the project files-->7. main_schema_class", I set the example as "Person", however, this would triger the test error.
C:\Users\kevin\OneDrive - The University Of Hong Kong\Desktop\LinkML\How_to\KS_LinkML>poetry run python -m unittest discover
E
======================================================================
ERROR: tests.test_data (unittest.loader._FailedTest.tests.test_data)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_data
Traceback (most recent call last):
File "C:\Users\kevin\AppData\Local\Programs\Python\Python312\Lib\unittest\loader.py", line 396, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\kevin\AppData\Local\Programs\Python\Python312\Lib\unittest\loader.py", line 339, in _get_module_from_name
__import__(name)
File "C:\Users\kevin\OneDrive - The University Of Hong Kong\Desktop\LinkML\How_to\KS_LinkML\tests\test_data.py", line 7, in <module>
from ks_linkml.datamodel.ks_linkml import PersonCollection
ImportError: cannot import name 'PersonCollection' from 'ks_linkml.datamodel.ks_linkml' (C:\Users\kevin\OneDrive - The University Of Hong Kong\Desktop\LinkML\How_to\KS_LinkML\src\ks_linkml\datamodel\ks_linkml.py)
Then I checked below two files:
..\teststest_data.py
"""Data test."""
import os
import glob
import unittest
from linkml_runtime.loaders import yaml_loader
from ks_linkml.datamodel.ks_linkml import PersonCollection
ROOT = os.path.join(os.path.dirname(__file__), '..')
DATA_DIR = os.path.join(ROOT, "src", "data", "examples")
EXAMPLE_FILES = glob.glob(os.path.join(DATA_DIR, '*.yaml'))
class TestData(unittest.TestCase):
"""Test data and datamodel."""
def test_data(self):
"""Data test."""
for path in EXAMPLE_FILES:
obj = yaml_loader.load(path, target_class=PersonCollection)
assert obj
But the example data ..\src\data\examples\Person-001.yaml is
# Example data object
---
entries:
- id: example:Person001
name: foo bar
primary_email: [email protected]
age_in_years: 33
However, the test_data.py expects the data to be in a PersonCollection format, which doesn't match the structure of my YAML file. To make it work, I had to adjust the test_data.py to manually load and parse the entries list from the YAML file.
Is the original test_data.py designed to work with a specific YAML structure? If so, could you provide an example of how the YAML file should be structured to match the PersonCollection format?
Thanks for your time!
The text was updated successfully, but these errors were encountered:
Hi there,
I recently cloned the example project from GitHub that uses Cookiecutter templates for generating the project structure. I encountered an issue with the test_data.py file when trying to validate my example YAML data.
In "Creating a new project-->Step 1: Generate the project files-->7. main_schema_class", I set the example as "Person", however, this would triger the test error.
Then I checked below two files:
..\teststest_data.py
But the example data ..\src\data\examples\Person-001.yaml is
However, the
test_data.py
expects the data to be in aPersonCollection
format, which doesn't match the structure of my YAML file. To make it work, I had to adjust thetest_data.py
to manually load and parse the entries list from the YAML file.Is the original
test_data.py
designed to work with a specific YAML structure? If so, could you provide an example of how the YAML file should be structured to match thePersonCollection
format?Thanks for your time!
The text was updated successfully, but these errors were encountered: