<commit_before>from core.models import Project
import unittest
import shutil
import pdb

class TestProject(unittest.TestCase):
    """docstring for TestProject"""
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_path(self):
        pass

if __name__ == '__main__':
    unittest.main()<commit_msg>add tests for Project, Module, App<commit_after>from core.models import Base, Project, Module, App, Task, Bcs, Instance
from core.models import CREATED
from core.models import BCS
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import unittest
import shutil
import pdb
import datetime
import os
import getpass

engine = create_engine('sqlite:///:memory:', echo=False)
Base.metadata.create_all(engine)

class TestProject(unittest.TestCase):
    """docstring for TestProject"""
    def setUp(self):
	self.Session = sessionmaker(bind=engine)
	self.session = self.Session()

    def tearDown(self):
	map(self.session.delete, self.session.query(Project).all())
	self.session.flush()
        self.session.close()

    def test_add(self):
	proj = Project(id='proj-id', name='test')
	self.session.add(proj)
	self.session.commit()

    def test_query(self):
        proj = self.session.query(Project).first()
	self.assertEqual(str(proj), "<Project(id=proj-id, name=test)>")
	self.assertEqual(proj.owner, getpass.getuser())
	self.assertEqual(proj.type, BCS)
	self.assertEqual(proj.status, CREATED)
	self.assertEqual(proj.start_date, None)
	self.assertEqual(len(proj.task), 0)

class TestModule(unittest.TestCase):
    """docstring for TestModule"""
    def setUp(self):
	self.Session = sessionmaker(bind=engine)
	self.session = self.Session()

    def tearDown(self):
	map(self.session.delete, self.session.query(Module).all())
	self.session.flush()
        self.session.close()

    def test_add(self):
        module = Module(name = 'Filter_rRNA', alias='Filter')
	self.session.add(module)
	self.session.commit()

    def test_query(self):
        module = self.session.query(Module).first()
	self.assertEqual(str(module), "<Module(id=1, name=Filter_rRNA)>")
	self.assertEqual(module.alias, "Filter")

class TestApp(unittest.TestCase):
    """docstring for TestModule"""
    def setUp(self):
	self.Session = sessionmaker(bind=engine)
	self.session = self.Session()

    def tearDown(self):
        self.session.close()

    def test_add(self):
        module = Module(name = 'Filter_rRNA', alias='Filter')
        app1 = App(name = 'RMrRNA_SOAP2', cpu=4, mem=8)
        app2 = App(name = 'RMrRNA_Statistic', cpu=1, mem=2)
	app1.module = module
	module.app.append(app2)
	self.session.add_all([app1, app2])
	self.session.commit()

    def test_query(self):
        module = self.session.query(Module).first()
        app = self.session.query(App).first()
	self.assertEqual(app.name, "RMrRNA_SOAP2")
	self.assertEqual(app.module.alias, "Filter")
	self.assertEqual(len(module.app), 2)
	self.assertEqual(module.app[1].name, "RMrRNA_Statistic")

if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.1385658914728682, 'fraction_numerical': 0.00516795865633075, 'mean_word_length': 4.376736111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1250233', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1008, 'n_words': 207}