コード例 #1
0
 def setup_method(self):
     # provide mountable tmp directory for docker
     tempfile.tempdir = "/tmp" if not platform.system(
     ) == "Windows" else None
     test_datmo_dir = os.environ.get('TEST_DATMO_DIR',
                                     tempfile.gettempdir())
     self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir)
     self.base = BaseController(home=self.temp_dir)
コード例 #2
0
 def test_failed_controller_instantiation(self):
     failed = False
     try:
         BaseController(home=os.path.join("does", "not", "exist"))
     except InvalidProjectPathException:
         failed = True
     assert failed
コード例 #3
0
 def test_failed_controller_instantiation(self):
     failed = False
     try:
         Config().set_home("does_not_exists")
         BaseController()
     except InvalidProjectPath:
         failed = True
     assert failed
コード例 #4
0
 def setup_method(self):
     self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir)
     Config().set_home(self.temp_dir)
     self.base_controller = BaseController()
コード例 #5
0
class TestBaseController():
    def setup_method(self):
        self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir)
        Config().set_home(self.temp_dir)
        self.base_controller = BaseController()

    def teardown_method(self):
        pass

    def test_failed_controller_instantiation(self):
        failed = False
        try:
            Config().set_home("does_not_exists")
            BaseController()
        except InvalidProjectPath:
            failed = True
        assert failed

    def test_instantiation(self):
        assert self.base_controller != None

    def test_datmo_model(self):
        # Test failure case
        assert self.base_controller.model == None

        # Test success case
        self.base_controller.dal.model.create(
            Model({
                "name": "test",
                "description": "test"
            }))
        model = self.base_controller.model

        assert model.id
        assert model.name == "test"
        assert model.description == "test"

    def test_current_session(self):
        # Test failure case
        failed = False
        try:
            _ = self.base_controller.current_session
        except DatmoModelNotInitialized:
            failed = True
        assert failed

        # Test success case
        self.base_controller.dal.model.create(
            Model({
                "name": "test",
                "description": "test"
            }))
        _ = self.base_controller.model
        self.base_controller.dal.session.create(
            Session({
                "name": "test",
                "model_id": "test",
                "current": True
            }))
        session = self.base_controller.current_session

        assert session.id
        assert session.name == "test"
        assert session.model_id == "test"
        assert session.current == True

    def test_default_code_driver(self):
        assert self.base_controller.code_driver != None
        assert self.base_controller.code_driver.type == "file"

    def test_default_file_driver(self):
        assert self.base_controller.file_driver != None
        assert self.base_controller.file_driver.type == "local"
        assert self.base_controller.file_driver.root == self.base_controller.home

    @pytest_docker_environment_failed_instantiation(test_datmo_dir)
    def test_default_environment_driver(self):
        assert self.base_controller.environment_driver != None
        assert self.base_controller.environment_driver.type == "docker"
        assert self.base_controller.environment_driver.filepath == self.base_controller.home

    def test_is_initialized(self):
        assert self.base_controller.is_initialized == \
               (self.base_controller.code_driver.is_initialized and \
               self.base_controller.file_driver.is_initialized and self.base_controller.model)

    def test_dal(self):
        assert self.base_controller.dal != None
        assert self.base_controller.dal.model != None

    def test_default_config_loader(self):
        # TODO: Test all Datmo default settings
        assert self.base_controller.config_loader("controller.code.driver")["constructor"] == \
               FileCodeDriver
        assert self.base_controller.config_loader("controller.file.driver")["constructor"] == \
               LocalFileDriver
        assert self.base_controller.config_loader("controller.environment.driver")["constructor"] == \
               DockerEnvironmentDriver

    def test_sanity_check_for_dal(self):
        model = self.base_controller.dal.model.create(Model({"name": "test"}))
        model2 = self.base_controller.dal.model.get_by_id(model.id)
        assert model and model2
        assert model.id == model2.id
コード例 #6
0
import os
import shutil
import uuid
import json
from flask import Flask, url_for
from flask import render_template, request, jsonify
import plotly
from datetime import datetime

from datmo.core.controller.base import BaseController
from datmo.monitoring import Monitoring

app = Flask(__name__)
base_controller = BaseController()
datmo_monitoring = Monitoring()


@app.route("/")
def home():
    user = {
        "name":
            "Shabaz Patel",
        "username":
            "******",
        "email":
            "*****@*****.**",
        "gravatar_url":
            "https://www.gravatar.com/avatar/" + str(uuid.uuid1()) +
            "?s=220&d=identicon&r=PG"
    }
    models = [base_controller.model.__dict__] if base_controller.model else []
コード例 #7
0
 def test_instantiation_with_home(self):
     test_controller = BaseController(home=os.getcwd())
     assert test_controller.home == os.getcwd()
コード例 #8
0
class TestBaseController():
    def setup_method(self):
        self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir)
        Config().set_home(self.temp_dir)
        self.base_controller = BaseController()
        self.project_controller = ProjectController()

    def teardown_method(self):
        pass

    def test_failed_controller_instantiation(self):
        failed = False
        try:
            Config().set_home("does_not_exists")
            BaseController()
        except InvalidProjectPath:
            failed = True
        assert failed

    def test_instantiation_with_home(self):
        test_controller = BaseController(home=os.getcwd())
        assert test_controller.home == os.getcwd()

    def test_instantiation(self):
        assert self.base_controller != None

    def test_datmo_model(self):
        # Test failure case
        assert self.base_controller.model == None

        # Test success case
        self.project_controller.init(name="test", description="test")
        model = self.base_controller.model

        assert model.id
        assert model.name == "test"
        assert model.description == "test"

    def test_default_code_driver_not_initialized(self):
        assert self.base_controller.code_driver != None
        assert self.base_controller.code_driver.type == "file"
        assert self.base_controller.code_driver.root == self.base_controller.home

    def test_default_file_driver_not_initialized(self):
        assert self.base_controller.file_driver != None
        assert self.base_controller.file_driver.type == "local"
        assert self.base_controller.file_driver.root == self.base_controller.home

    @pytest_docker_environment_failed_instantiation(test_datmo_dir)
    def test_default_environment_driver_not_initialized(self):
        assert self.base_controller.environment_driver != None
        assert self.base_controller.environment_driver.type == "docker"
        assert self.base_controller.environment_driver.root == self.base_controller.home

    def test_is_initialized(self):
        assert self.base_controller.is_initialized == \
               (self.base_controller.code_driver.is_initialized and \
               self.base_controller.file_driver.is_initialized and \
                self.base_controller.environment_driver.is_initialized and \
                self.base_controller.model)

    def test_dal_not_initialized(self):
        assert self.base_controller.dal != None
        thrown = False
        try:
            self.base_controller.dal.model == None
        except DALNotInitialized:
            thrown = True
        assert thrown

    def test_dal_initialized(self):
        self.project_controller.init(name="test", description="test")
        assert self.base_controller.dal != None
        assert self.base_controller.model != None

    def test_default_config_loader(self):
        # TODO: Test all Datmo default settings
        assert self.base_controller.config_loader("controller.code.driver")["constructor"] == \
               FileCodeDriver
        assert self.base_controller.config_loader("controller.file.driver")["constructor"] == \
               LocalFileDriver
        assert self.base_controller.config_loader("controller.environment.driver")["constructor"] == \
               DockerEnvironmentDriver

    def test_sanity_check_for_dal(self):
        self.project_controller.init(name="test", description="test")
        model = self.base_controller.model
        model2 = self.base_controller.dal.model.get_by_id(model.id)
        assert model and model2
        assert model.id == model2.id
コード例 #9
0
class TestBaseController():
    def setup_method(self):
        # provide mountable tmp directory for docker
        tempfile.tempdir = "/tmp" if not platform.system(
        ) == "Windows" else None
        test_datmo_dir = os.environ.get('TEST_DATMO_DIR',
                                        tempfile.gettempdir())
        self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir)
        self.base = BaseController(home=self.temp_dir)

    def teardown_method(self):
        pass

    def test_failed_controller_instantiation(self):
        failed = False
        try:
            BaseController(home=os.path.join("does", "not", "exist"))
        except InvalidProjectPathException:
            failed = True
        assert failed

    def test_instantiation(self):
        assert self.base != None

    def test_datmo_model(self):
        # Test failure case
        assert self.base.model == None

        # Test success case
        self.base.dal.model.create(
            Model({
                "name": "test",
                "description": "test"
            }))
        model = self.base.model

        assert model.id
        assert model.name == "test"
        assert model.description == "test"

    def test_current_session(self):
        # Test failure case
        failed = False
        try:
            _ = self.base.current_session
        except DatmoModelNotInitializedException:
            failed = True
        assert failed

        # Test success case
        self.base.dal.model.create(
            Model({
                "name": "test",
                "description": "test"
            }))
        _ = self.base.model
        self.base.dal.session.create(
            Session({
                "name": "test",
                "model_id": "test",
                "current": True
            }))
        session = self.base.current_session

        assert session.id
        assert session.name == "test"
        assert session.model_id == "test"
        assert session.current == True

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

    def test_file_tree(self):
        assert self.base.file_driver != None
        assert self.base.file_driver.filepath == self.base.home

    def test_environment(self):
        assert self.base.environment_driver != None
        assert self.base.environment_driver.filepath == self.base.home

    def test_dal(self):
        assert self.base.dal != None
        assert self.base.dal.model != None

    def test_config_loader(self):
        # TODO: Test all Datmo default settings
        assert self.base.config_loader("controller.code.driver")["constructor"] == \
               GitCodeDriver

    def test_sanity_check_for_dal(self):
        model = self.base.dal.model.create(Model({"name": "test"}))
        model2 = self.base.dal.model.get_by_id(model.id)
        assert model and model2
        assert model.id == model2.id