Skip to content

Commit

Permalink
Initial work for distributed evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
christophertubbs authored and robertbartel committed Feb 2, 2024
1 parent e1988e1 commit 576fb10
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 15 deletions.
2 changes: 1 addition & 1 deletion python/lib/core/dmod/core/common/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DescribableProtocol(typing.Protocol):

# Strictly speaking, this should be a Sequence, but the type system does
# not support fixed-length sequences.
DBAPIColumnDescription: typing.TypeAlias = tuple[
DBAPIColumnDescription: typing.TypeAlias = typing.Tuple[
str,
DBAPITypeCode,
typing.Optional[int],
Expand Down
2 changes: 0 additions & 2 deletions python/lib/evaluations/dmod/evaluations/specification/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

from ..utilities import merge_dictionaries

from .template import TemplateManager

from .. import util

from .helpers import is_a_value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ class SpecificationTemplateForm(forms.ModelForm):
"""
A specialized form for SpecificationTemplate that allows its JSON data to be manipulated within a JSONArea
"""
class Meta:
model = models.SpecificationTemplate
fields = [
field.name
for field in models.SpecificationTemplate._meta.get_fields()
if field.name.lower() not in ("owner", "author")
]
#class Meta:
# model = models.SpecificationTemplate
# fields = [
# field.name
# for field in models.SpecificationTemplate._meta.get_fields()
# if field.name.lower() not in ("owner", "author")
# ]

class Media:
# Include a script to add functionality that will update the json area's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import typing
import sqlite3
from collections import defaultdict
import re

from dmod.core.common import DBAPIConnection
Expand All @@ -28,7 +27,6 @@ class SpecificationTemplateManager(TemplateManager):
"""
Object manager used to provide details about available templates defined within the Django DB instance
"""
def get_templates(self, specification_type: str) -> typing.Sequence[TemplateDetails]:
def __init__(self, *args, **kwargs):
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUpTestData(cls):

cls.token = Token.objects.create(user=cls.test_user)

cls.manager = FileTemplateManager(manifest_path=TEMPLATE_MANIFEST_PATH)
cls.manager = FileTemplateManager(path=TEMPLATE_MANIFEST_PATH)

for template_details_group in cls.manager.get_all_templates().values():
for template_details in template_details_group:
Expand Down Expand Up @@ -253,7 +253,6 @@ def test_search_templates(self):

self.assertIsNotNone(matching_template)


def test_get_all_templates(self):
get_response = self.client.get(
"/evaluation_service/templates/"
Expand All @@ -269,7 +268,7 @@ def test_get_all_templates(self):
templates = get_data['templates']

self.assertTrue(isinstance(templates, typing.Mapping))
self.assertEqual(len(templates), 9)
self.assertEqual(len(templates), 12)

self.assertIn("BackendSpecification", templates)
self.assertIn("FieldMappingSpecification", templates)
Expand All @@ -280,6 +279,9 @@ def test_get_all_templates(self):
self.assertIn("ThresholdDefinition", templates)
self.assertIn("ThresholdApplicationRules", templates)
self.assertIn("EvaluationSpecification", templates)
self.assertIn("CrosswalkSpecification", templates)
self.assertIn("DataSourceSpecification", templates)
self.assertIn("ThresholdSpecification", templates)

self.assertEqual(len(templates['BackendSpecification']), 4)
self.assertEqual(len(templates['FieldMappingSpecification']), 3)
Expand All @@ -290,6 +292,9 @@ def test_get_all_templates(self):
self.assertEqual(len(templates['ThresholdDefinition']), 3)
self.assertEqual(len(templates['ThresholdApplicationRules']), 1)
self.assertEqual(len(templates['EvaluationSpecification']), 5)
self.assertEqual(len(templates['CrosswalkSpecification']), 2)
self.assertEqual(len(templates["DataSourceSpecification"]), 4)
self.assertEqual(len(templates["ThresholdSpecification"]), 2)

post_response = self.client.post(
"/evaluation_service/templates/"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from pathlib import Path

from django.test import TestCase

from dmod.evaluations.specification import TemplateManager
from evaluation_service import specification


# Create your tests here.
class SpecificationTemplateManager(TestCase):
"""
Tests to ensure that the SpecificationTemplateManager operates as expected, especially when it comes to exports
"""
control_manager: specification.SpecificationTemplateManager
export_directory: Path

@classmethod
def setUpClass(cls) -> None:
"""
Set up the SpecificationTemplateManager that serves as a control for the tests and form the export path
"""
super().setUpClass()
cls.export_directory = Path(__file__).parent / 'data' / 'writing' / cls.__name__
cls.export_directory.mkdir(parents=True, exist_ok=True)

@classmethod
def tearDownClass(cls) -> None:
"""
Remove all artifacts generated by this test
"""
super().tearDownClass()
cls.export_directory.rmdir()

def test_database_export(self):
"""
Test to ensure that `self.control_manager.export_database` works
"""
...

def test_inmemory_export(self):
"""
Test to ensure that the contents of the control_manager can be exported into an inmemory object and reloaded
into another manager
"""
...

def test_file_export(self):
"""
Test to ensure that the contents of the control manager can be correctly exported to files
"""
...

def test_file_imports(self):
"""
Test the control_manager to ensure that its contents are correct for the other tests
"""
self.verify_templatemanager_contents(self.control_manager)

def verify_templatemanager_contents(self, manager: TemplateManager):
"""
Ensure that the passed in manager contain the correct contents
Args:
manager: The manager whose contents to test
"""
...

0 comments on commit 576fb10

Please sign in to comment.