Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion checklist/abstract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def formatz(x):
class AbstractTest(ABC):
def __init__(self, data, expect, labels=None, meta=None, agg_fn='all',
templates=None, print_first=None, name=None, capability=None,
description=None):
description=None, test_id=None):
self.data = data
self.expect = expect
self.labels = labels
Expand All @@ -80,6 +80,7 @@ def __init__(self, data, expect, labels=None, meta=None, agg_fn='all',
self.name = name
self.capability = capability
self.description = description
self.test_id = test_id
def save(self, file):
dill.dump(self, open(file, 'wb'), recurse=True)

Expand Down
18 changes: 12 additions & 6 deletions checklist/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class MFT(AbstractTest):
def __init__(self, data, expect=None, labels=None, meta=None, agg_fn='all',
templates=None, name=None, capability=None, description=None):
templates=None, name=None, capability=None, description=None, test_id=None):
"""Minimum Functionality Test

Parameters
Expand All @@ -28,19 +28,21 @@ def __init__(self, data, expect=None, labels=None, meta=None, agg_fn='all',
test capability
description : str
test description
test_id: str
test case identifier
"""
if labels is None and expect is None:
raise(Exception('Must specify either \'expect\' or \'labels\''))
if labels is not None and expect is None:
expect = Expect.eq()
super().__init__(data, expect, labels=labels, meta=meta, agg_fn=agg_fn,
templates=templates, print_first=False, name=name,
capability=capability, description=description)
capability=capability, description=description, test_id=test_id)

class INV(AbstractTest):
def __init__(self, data, expect=None, threshold=0.1, meta=None,
agg_fn='all_except_first', templates=None, name=None,
capability=None, description=None, labels=None):
capability=None, description=None, labels=None, test_id=None):
"""Invariance Test

Parameters
Expand Down Expand Up @@ -69,16 +71,18 @@ def __init__(self, data, expect=None, threshold=0.1, meta=None,
test description
labels : single value (int, str, etc) or list
If list, must be the same length as data
test_id: str
test case identifier
"""
if expect is None:
expect = Expect.inv(threshold)
super().__init__(data, expect, labels=labels, meta=meta, agg_fn=agg_fn,
templates=templates, print_first=True, name=name,
capability=capability, description=description)
capability=capability, description=description, test_id=test_id)

class DIR(AbstractTest):
def __init__(self, data, expect, meta=None, agg_fn='all_except_first',
templates=None, name=None, labels=None, capability=None, description=None):
templates=None, name=None, labels=None, capability=None, description=None, test_id=None):
"""Directional Expectation Test

Parameters
Expand All @@ -103,7 +107,9 @@ def __init__(self, data, expect, meta=None, agg_fn='all_except_first',
test capability
description : str
test description
test_id: str
test case identifier
"""
super().__init__(data, expect, labels=labels, meta=meta, agg_fn=agg_fn,
templates=templates, print_first=True, name=name,
capability=capability, description=description)
capability=capability, description=description, test_id=test_id)
51 changes: 51 additions & 0 deletions tests/test_test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""unit tests for test suite creation with different test types"""
from unittest import TestCase
from checklist.test_types import MFT, DIR, INV
from checklist.editor import Editor
from checklist.expect import Expect


class TestTestTypes(TestCase):
editor = Editor()
dummy_test_data = editor.template(
templates=["example 1", "example 2"], meta=False, labels=["label1", "label2"])
test_id = "100"

def test_mft_w_test_id(self):
mft_test = MFT(**self.dummy_test_data,
expect=Expect.eq(),
name="mft test with test id",
test_id=self.test_id)
assert mft_test.test_id == self.test_id

def test_mft_wo_test_id(self):
mft_test = MFT(**self.dummy_test_data,
expect=Expect.eq(),
name="mft test without test id")
assert mft_test.test_id is None

def test_dir_w_test_id(self):
dir_test = DIR(**self.dummy_test_data,
expect=Expect.eq(),
name="dir test with test id",
test_id=self.test_id)
assert dir_test.test_id == self.test_id

def test_dir_wo_test_id(self):
dir_test = DIR(**self.dummy_test_data,
expect=Expect.eq(),
name="dir test without test id")
assert dir_test.test_id is None

def test_inv_w_test_id(self):
inv_test = INV(**self.dummy_test_data,
expect=Expect.eq(),
name="inv test with test id",
test_id=self.test_id)
assert inv_test.test_id == self.test_id

def test_inv_wo_test_id(self):
inv_test = INV(**self.dummy_test_data,
expect=Expect.eq(),
name="inv test without test id")
assert inv_test.test_id is None