Skip to content

Commit

Permalink
add in testing for entities
Browse files Browse the repository at this point in the history
  • Loading branch information
asampat3090 committed Apr 10, 2018
1 parent 76a60e8 commit f2411be
Show file tree
Hide file tree
Showing 20 changed files with 409 additions and 24 deletions.
7 changes: 3 additions & 4 deletions datmo/controller/test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Tests for BaseController
"""
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import shutil
Expand All @@ -17,8 +16,8 @@
class TestBaseController():
def setup_method(self):
# provide mountable tmp directory for docker
tempfile.tempdir = '/tmp'
self.temp_dir = tempfile.mkdtemp('datmo_project')
tempfile.tempdir = "/tmp"
self.temp_dir = tempfile.mkdtemp("datmo_project")
self.base = BaseController(self.temp_dir)

def teardown_method(self):
Expand All @@ -38,7 +37,7 @@ def test_current_session(self):

def test_code_manager(self):
assert self.base.code_driver != None
assert self.base.code_driver.type == 'git'
assert self.base.code_driver.type == "git"

def test_file_tree(self):
assert self.base.file_driver != None
Expand Down
2 changes: 1 addition & 1 deletion datmo/entity/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, dictionary):
def __eq__(self, other):
return self.id == other.id if other else False

def toDictionary(self):
def to_dictionary(self):
attr_dict = self.__dict__
pruned_attr_dict = { attr: val
for attr, val in attr_dict.items() if not callable(getattr(self, attr)) and not attr.startswith("__")
Expand Down
2 changes: 1 addition & 1 deletion datmo/entity/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, dictionary):
def __eq__(self, other):
return self.id == other.id if other else False

def toDictionary(self):
def to_dictionary(self):
attr_dict = self.__dict__
pruned_attr_dict = { attr: val
for attr, val in attr_dict.items() if not callable(getattr(self, attr)) and not attr.startswith("__")
Expand Down
8 changes: 4 additions & 4 deletions datmo/entity/file_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ class FileCollection():
Attributes
----------
id : str
model_id : str
path : str
driver_type : str
model_id : str
created_at : datetime
updated_at : datetime
"""
def __init__(self, dictionary):
self.id = dictionary['id']
self.model_id = dictionary['model_id']

self.path = dictionary['path']
self.driver_type = dictionary['driver_type']

self.model_id = dictionary['model_id']

self.created_at = dictionary.get('created_at', datetime.utcnow())
self.updated_at = dictionary.get('updated_at', self.created_at)

def __eq__(self, other):
return self.id == other.id if other else False

def toDictionary(self):
def to_dictionary(self):
attr_dict = self.__dict__
pruned_attr_dict = { attr: val
for attr, val in attr_dict.items() if not callable(getattr(self, attr)) and not attr.startswith("__")
Expand Down
2 changes: 1 addition & 1 deletion datmo/entity/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, dictionary):
def __eq__(self, other):
return self.id == other.id if other else False

def toDictionary(self):
def to_dictionary(self):
attr_dict = self.__dict__
pruned_attr_dict = { attr: val
for attr, val in attr_dict.items() if not callable(getattr(self, attr)) and not attr.startswith("__")
Expand Down
7 changes: 4 additions & 3 deletions datmo/entity/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@ class Session():
Attributes
----------
id : str
name : str
model_id : str
name : str
created_at : datetime
updated_at : datetime
"""
def __init__(self, dictionary):
self.id = dictionary['id']
self.name = dictionary['name']
self.model_id = dictionary['model_id']

self.name = dictionary['name']

self.created_at = dictionary.get('created_at', datetime.utcnow())
self.updated_at = dictionary.get('updated_at', self.created_at)

def __eq__(self, other):
return self.id == other.id if other else False

def toDictionary(self):
def to_dictionary(self):
attr_dict = self.__dict__
pruned_attr_dict = { attr: val
for attr, val in attr_dict.items() if not callable(getattr(self, attr)) and not attr.startswith("__")
Expand Down
2 changes: 1 addition & 1 deletion datmo/entity/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def save_stats(self, filepath):
self.stats)
return

def toDictionary(self):
def to_dictionary(self):
attr_dict = self.__dict__
pruned_attr_dict = { attr: val
for attr, val in attr_dict.items() if not callable(getattr(self, attr)) and not attr.startswith("__")
Expand Down
2 changes: 1 addition & 1 deletion datmo/entity/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, dictionary):
def __eq__(self, other):
return self.id == other.id if other else False

def toDictionary(self):
def to_dictionary(self):
attr_dict = self.__dict__
pruned_attr_dict = { attr: val
for attr, val in attr_dict.items() if not callable(getattr(self, attr)) and not attr.startswith("__")
Expand Down
Empty file added datmo/entity/test/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions datmo/entity/test/test_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Tests for Code
"""
from datmo.entity.code import Code


class TestCode():
def test_init(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"driver_type": "git",
}
code_entity = Code(input_dict)

for k, v in input_dict.items():
assert getattr(code_entity, k) == v
assert code_entity.created_at
assert code_entity.updated_at

def test_eq(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"driver_type": "git",
}
code_entity_1 = Code(input_dict)
code_entity_2 = Code(input_dict)
assert code_entity_1 == code_entity_2

def test_to_dictionary(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"driver_type": "git",
}
code_entity = Code(input_dict)
output_dict = code_entity.to_dictionary()

for k, v in output_dict.items():
assert v == getattr(code_entity, k)
49 changes: 49 additions & 0 deletions datmo/entity/test/test_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Tests for Environment
"""
from datmo.entity.environment import Environment


class TestEnvironment():
def test_init(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"driver_type": "docker",
"file_collection_id": "my_collection",
"definition_filename": "Dockerfile"
}
environment_entity = Environment(input_dict)

for k, v in input_dict.items():
assert getattr(environment_entity, k) == v
assert environment_entity.description == ""
assert environment_entity.created_at
assert environment_entity.updated_at

def test_eq(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"driver_type": "docker",
"file_collection_id": "my_collection",
"definition_filename": "Dockerfile"
}
environment_entity_1 = Environment(input_dict)
environment_entity_2 = Environment(input_dict)

assert environment_entity_1 == environment_entity_2

def test_to_dictionary(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"driver_type": "docker",
"file_collection_id": "my_collection",
"definition_filename": "Dockerfile"
}
environment_entity = Environment(input_dict)
output_dict = environment_entity.to_dictionary()

for k, v in output_dict.items():
assert v == getattr(environment_entity, k)
44 changes: 44 additions & 0 deletions datmo/entity/test/test_file_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Tests for FileCollection
"""
from datmo.entity.file_collection import FileCollection


class TestFileCollection():
def test_init(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"path": "/path/to/file",
"driver_type": "docker",
}
file_collection_entity = FileCollection(input_dict)

for k, v in input_dict.items():
assert getattr(file_collection_entity, k) == v
assert file_collection_entity.created_at
assert file_collection_entity.updated_at

def test_eq(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"path": "/path/to/file",
"driver_type": "docker",
}
file_collection_entity_1 = FileCollection(input_dict)
file_collection_entity_2 = FileCollection(input_dict)
assert file_collection_entity_1 == file_collection_entity_2

def test_to_dictionary(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"path": "/path/to/file",
"driver_type": "docker",
}
file_collection_entity = FileCollection(input_dict)
output_dict = file_collection_entity.to_dictionary()

for k, v in output_dict.items():
assert v == getattr(file_collection_entity, k)
40 changes: 40 additions & 0 deletions datmo/entity/test/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Tests for Model
"""
from datmo.entity.model import Model


class TestModel():
def test_init(self):
input_dict = {
"id": "test",
"name": "test"
}
model_entity = Model(input_dict)

for k, v in input_dict.items():
assert getattr(model_entity, k) == v
assert model_entity.description == ""
assert model_entity.created_at
assert model_entity.updated_at

def test_eq(self):
input_dict = {
"id": "test",
"name": "test"
}
model_entity_1 = Model(input_dict)
model_entity_2 = Model(input_dict)

assert model_entity_1 == model_entity_2

def test_to_dictionary(self):
input_dict = {
"id": "test",
"name": "test",
}
model_entity = Model(input_dict)
output_dict = model_entity.to_dictionary()

for k, v in output_dict.items():
assert v == getattr(model_entity, k)
42 changes: 42 additions & 0 deletions datmo/entity/test/test_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Tests for Session
"""
from datmo.entity.session import Session


class TestSession():
def test_init(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"name": "test"
}
session_entity = Session(input_dict)

for k, v in input_dict.items():
assert getattr(session_entity, k) == v
assert session_entity.created_at
assert session_entity.updated_at

def test_eq(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"name": "test"
}
session_entity_1 = Session(input_dict)
session_entity_2 = Session(input_dict)

assert session_entity_1 == session_entity_2

def test_to_dictionary(self):
input_dict = {
"id": "test",
"model_id": "my_model",
"name": "test"
}
session_entity = Session(input_dict)
output_dict = session_entity.to_dictionary()

for k, v in output_dict.items():
assert v == getattr(session_entity, k)

0 comments on commit f2411be

Please sign in to comment.