Skip to content

Commit

Permalink
ENH: Setup intial base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ellisdg committed Dec 13, 2016
0 parents commit 13b9c43
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
*.pyc
Empty file added bids/__init__.py
Empty file.
Empty file added bids/base/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions bids/base/dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


class DataSet(object):
def __init__(self, subjects=None):
self.subjects = []
if subjects:
for subject in subjects:
self.add_subject(subject)

def add_subject(self, subject):
if subject.get_id() not in self.list_subject_ids():
self.subjects.append(subject)
else:
raise(ValueError("Duplicate subject subject_id found."))

def list_subject_ids(self):
return [subject.get_id() for subject in self.subjects]

def get_number_of_subjects(self):
return len(self.subjects)
8 changes: 8 additions & 0 deletions bids/base/group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


class Group(object):
def __init__(self):
self._images = []

def add_image(self, image):
self._images.append(image)
5 changes: 5 additions & 0 deletions bids/base/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Image(object):
def __init__(self, file_path=None, side_car_path=None):
self.file_path = file_path
self.side_car_path = side_car_path

8 changes: 8 additions & 0 deletions bids/base/session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


class Session(object):
def __init__(self):
self._groups = []

def add_group(self, group):
self._groups.append(group)
12 changes: 12 additions & 0 deletions bids/base/subject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


class Subject(object):
def __init__(self, subject_id=None):
self.subject_id = subject_id
self.sessions = []

def add_session(self, session):
self.sessions.append(session)

def get_id(self):
return self.subject_id
Empty file added bids/test/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions bids/test/test_dataSet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
from unittest import TestCase
from ..base.dataset import DataSet
from ..base.subject import Subject


class TestDataSet(TestCase):
def test_add_subject(self):
dataset = DataSet()
dataset.add_subject(Subject())

def test_number_of_subjects(self):
dataset = DataSet(subjects=[Subject("001"), Subject("002")])
self.assertEqual(dataset.get_number_of_subjects(), 2)

def test_enforce_unique_ids(self):
dataset = DataSet()
subject_1 = Subject("001")
dataset.add_subject(subject_1)
subject_2 = Subject("001")
with self.assertRaises(ValueError):
dataset.add_subject(subject_2)

if __name__ == "__main__":
unittest.main()
16 changes: 16 additions & 0 deletions bids/test/test_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest
from unittest import TestCase
from bids.base.group import Group
from bids.base.image import Image


class TestGroup(TestCase):
def setUp(self):
self.group = Group()

def test_add_image(self):
image = Image()
self.group.add_image(image)

if __name__ == '__main__':
unittest.main()
5 changes: 5 additions & 0 deletions bids/test/test_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from unittest import TestCase


class TestImage(TestCase):
pass
15 changes: 15 additions & 0 deletions bids/test/test_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest
from unittest import TestCase
from ..base.session import Session
from ..base.group import Group


class TestSession(TestCase):

def test_add_group(self):
session = Session()
session.add_group(Group())


if __name__ == "__main__":
unittest.main()
14 changes: 14 additions & 0 deletions bids/test/test_subject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest
from unittest import TestCase
from ..base.session import Session
from ..base.subject import Subject


class TestSubject(TestCase):
def test_add_session(self):
subject = Subject()
subject.add_session(Session())


if __name__ == "__main__":
unittest.main()

0 comments on commit 13b9c43

Please sign in to comment.