Ejemplo n.º 1
0
    def test_task_entity_results(self):
        core_task_entity = CoreTask(self.input_dict)
        task_entity = Task(core_task_entity)
        # Test failure because entity has not been created by controller
        failed = False
        try:
            task_entity.results
        except DoesNotExist:
            failed = True
        assert failed
        # Test success
        task_entity = self.__setup()
        result = task_entity.results

        assert result == None
Ejemplo n.º 2
0
    def test_task_entity_logs(self):
        core_task_entity = CoreTask(self.input_dict)
        task_entity = Task(core_task_entity)
        # Test failure because entity has not been created by controller
        failed = False
        try:
            task_entity.logs
        except DoesNotExist:
            failed = True
        assert failed
        # Test success
        task_entity = self.__setup()
        result = task_entity.logs

        assert result
        assert isinstance(result, to_unicode)
Ejemplo n.º 3
0
    def test_task_entity_files(self):
        core_task_entity = CoreTask(self.input_dict)
        task_entity = Task(core_task_entity)
        # Test failure because entity has not been created by controller
        failed = False
        try:
            task_entity.files
        except DoesNotExist:
            failed = True
        assert failed
        # Test success
        task_entity = self.__setup()
        result = task_entity.files

        assert len(result) == 1
        assert isinstance(result[0], TextIOWrapper)
        assert result[0].mode == "r"
        assert result[0].name
Ejemplo n.º 4
0
    def test_task_entity_instantiate(self):
        input_dict = {
            "id": "test",
            "model_id": "my_model",
            "session_id": "my_session",
            "command": "python test.py"
        }
        core_task_entity = CoreTask(input_dict)
        task_entity = Task(core_task_entity, home=self.temp_dir)

        for k, v in input_dict.items():
            assert getattr(task_entity, k) == v
        assert task_entity.status == None
        assert task_entity.start_time == None
        assert task_entity.end_time == None
        assert task_entity.duration == None
        assert task_entity.logs == None
        assert task_entity.results == None
Ejemplo n.º 5
0
    def test_task_entity_files(self):
        input_dict = {
            "id": "test",
            "model_id": "my_model",
            "session_id": "my_session",
            "command": "python test.py"
        }
        core_task_entity = CoreTask(input_dict)
        task_entity = Task(core_task_entity, home=self.temp_dir)
        # Test failure because entity has not been created by controller
        failed = False
        try:
            task_entity.files()
        except EntityNotFound:
            failed = True
        assert failed

        # Create a basic task and run it with string command
        test_filepath = os.path.join(self.temp_dir, "script.py")
        with open(test_filepath, "w") as f:
            f.write(to_unicode("import numpy\n"))
            f.write(to_unicode("import sklearn\n"))
            f.write(to_unicode("print 'hello'\n"))

        test_filepath = os.path.join(self.temp_dir, "Dockerfile")
        with open(test_filepath, "w") as f:
            f.write(to_unicode("FROM datmo/xgboost:cpu"))

        task_entity = run(command="python script.py",
                          env=test_filepath,
                          home=self.temp_dir)
        result = task_entity.files()

        assert len(result) == 1
        assert isinstance(result[0], TextIOWrapper)
        assert result[0].name
Ejemplo n.º 6
0
    def test_task_entity_instantiate(self):
        core_task_entity = CoreTask(self.input_dict)
        task_entity = Task(core_task_entity)

        for k, v in self.input_dict.items():
            assert getattr(task_entity, k) == v