def __init__(self, config_path: str = None, config_fn: str = 'akk.ini'): # self._config = configparser.ConfigParser() # if config_path is None: # config_path = os.path.join(os.getcwd(), '.akk') # if config_fn is None: # config_fn = 'config.ini' # file_path = os.path.join(config_path, config_fn) # assert os.path.isfile(file_path) # self._config.read(file_path) # project_id = self.get_parameter('database', 'project_id') # experience_id = self.get_parameter('database', 'experience_id') self._orm = MongodbORM()
from akk.cli.project import init_project from akk.lib.exception import NoRepoException from akk.lib.services import MongodbORM def random_string(length: int = 10, spaces: bool = True, digits: bool = True) -> str: """Generate a random string of fixed length """ letters = string.ascii_letters if spaces: letters += ' ' if digits: letters += string.digits return ''.join(random.choice(letters) for _ in range(length)) orm = MongodbORM() abs_path = '/home/bothmena/Projects/PyCharm/BrighterAI/autonomous-kaggle-kernels/examples' project_dir = 'test_project' project_path = os.path.join(abs_path, project_dir) class ProjectInitTestSuite(TestCase): project_temp = { 'name' : None, 'alias' : None, 'path' : None, 'repository' : None, 'framework' : 'pytorch', 'cpu' : False, 'internet' : False, 'entrypoint' : 'main.py',
def test_singleton(self): a = MongodbORM() b = MongodbORM() self.assertEqual(a, b)
class MongoDBTest(TestCase): project = { 'name': 'test project', 'alias': 'test project', 'path': '/tmp/test_akk_project', 'repository': None, 'entrypoint': 'main.py', 'framework': 'tensorflow', 'datasets': [], 'kernels': [], 'competitions': [], 'cpu': False, 'internet': False, 'private': False, 'type': 'notebook', 'date': datetime.now(), } # todo: update experience attributes experience = { 'search_space': None, 'batch_size': 64, 'status': 'running', 'git_commit': 'a654as4df5', 'optimizer': 'adam', 'opt_args': { 'arg1': 5, 'arg2': 'str' }, 'networks': { 'main_net': { 'lr': 'cross_entropy', 'lr_decay': 'cross_entropy', 'lr_cycle': 'cross_entropy', 'loss': 'cross_entropy', 'loss_args': { 'arg1': 5, 'arg2': 'str' }, } }, 'cycles': { "main_cycle": { "steps": 200, "unit_running_time": None } }, 'date': datetime.now(), } db = MongodbORM() if not os.path.isdir(project['path']): os.mkdir(project['path']) prj = db.get_project(project['path']) if prj is not None: db.projects.delete_one({'_id': prj['_id']}) def test_singleton(self): a = MongodbORM() b = MongodbORM() self.assertEqual(a, b) def test_new_project(self): uid = self.db.new_project(self.project) project_db = self.db.projects.find_one({'_id': uid}) keys = list(self.project.keys()) keys.pop(keys.index('date')) for key in keys: self.assertEqual(self.project[key], project_db[key]) self.db.projects.delete_one({'_id': uid}) def test_get_project(self): uid = self.db.new_project(self.project) project_db = self.db.get_project(self.project['path']) keys = list(self.project.keys()) keys.pop(keys.index('date')) for key in keys: self.assertEqual(self.project[key], project_db[key]) self.db.projects.delete_one({'_id': uid}) def test_unique_name(self): uid = self.db.new_project(self.project) self.assertRaises(ProjectExistsException, self.db.new_project, self.project) self.db.projects.delete_one({'_id': uid}) def test_new_experience(self): p_uid = self.db.new_project(self.project) self.experience['project'] = p_uid e_uid = self.db.new_experience(self.experience) exp_db = self.db.experiences.find_one({'_id': e_uid}) project = self.db.projects.find_one({'_id': p_uid}) keys = list(self.experience.keys()) + ['project'] keys.pop(keys.index('date')) for key in keys: self.assertEqual(self.experience[key], exp_db[key]) name = project['alias'] + ' ' + str(exp_db['_id']) self.assertIsInstance(exp_db['project'], ObjectId) self.assertEqual(exp_db['kernel_name'], name) self.assertEqual(exp_db['kernel_id'], 'bothmena/' + slugify(name)) self.db.experiences.delete_one({'_id': e_uid}) self.db.projects.delete_one({'_id': p_uid}) def test_unique_experience(self): p_uid = self.db.new_project(self.project) self.experience['project'] = p_uid e_uid = self.db.new_experience(self.experience) self.assertRaises(ExperienceExistsException, self.db.new_experience, self.experience) self.experience['search_space'] = p_uid self.assertRaises(ExperienceExistsException, self.db.new_experience, self.experience) self.db.experiences.delete_one({'_id': e_uid}) self.db.projects.delete_one({'_id': p_uid}) def test_get_experience(self): p_uid = self.db.new_project(self.project) self.experience['project'] = p_uid e_uid = self.db.new_experience(self.experience) exp_db = self.db.get_experience(str(e_uid)) keys = list(self.experience.keys()) + ['project'] keys.pop(keys.index('date')) for key in keys: self.assertEqual(self.experience[key], exp_db[key]) self.db.experiences.delete_one({'_id': e_uid}) self.db.projects.delete_one({'_id': p_uid})