Exemple #1
0
    def _gen_false_local_retrieve(self):
        """Create a local retrieve for a single solver in a temp directory"""
        # Create the temp dir
        temp_dir = tempfile.mkdtemp()
        # Create the temp task
        name = os.path.split(self.solver_override)[1]
        id = str(uuid.uuid1())
        logging.debug('Creating a task for {} named {}, id {}'.format(
            self.solver_override, name, id))

        temp_task = os.path.join(temp_dir, 'task.json')
        with open(temp_task, 'w') as f:
            train_directive = [{
                'type': 'train',
                'parameters': {
                    'solver': self.solver_override
                }
            }]
            task_file = {
                'directives': train_directive,
                'title': name,
                'id': id
            }
            json.dump(task_file, f)
        # Create the temp list containing one task
        temp_task_list = tempfile.NamedTemporaryFile()
        print(temp_task, file=temp_task_list)
        logging.debug('Created task list with single task at {}'.format(
            temp_task_list.name))
        return LocalRetrieve(temp_task_list.name)
class TestLocalRetrieve(unittest.TestCase):
    _test_task = """{
        "directives": [{
            "type": "train",
            "parameters": {
            "model": "/home/user/folder/002/model.prototxt",
            "solver": "/home/user/folder/002/solver.prototxt"
            }
        }],
        "name": "mri.Test",
        "id": "554d0b8888fce10300bf0bdf"
    }"""

    def setUp(self):
        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(bytes(self._test_task, 'UTF-8'))
        f.close()
        self.taskfile = f.name

        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(bytes(self.taskfile, 'UTF-8'))
        f.close()
        self.listfile = f.name

    def tearDown(self):
        os.remove(self.taskfile)
        os.remove(self.listfile)

    def test_local_retrieve_file(self):
        self.instance = LocalRetrieve(self.listfile)
        test_str = "/home/testuser/folder/folder/model.prototxt"
        ident = self.instance.retrieve_file(test_str)
        self.assertEqual(ident, test_str)

    def test_local_retrieve_task(self):
        self.instance = LocalRetrieve(self.listfile)
        for task in self.instance.retrieve_task():
            self.assertEqual(task['id'], '554d0b8888fce10300bf0bdf')
            self.assertEqual(len(task['directives']), 1)
class TestLocalRetrieve(unittest.TestCase):
    _test_task = """{
        "directives": [{
            "type": "train",
            "parameters": {
            "model": "/home/user/folder/002/model.prototxt",
            "solver": "/home/user/folder/002/solver.prototxt"
            }
        }],
        "name": "mri.Test",
        "id": "554d0b8888fce10300bf0bdf"
    }"""

    def setUp(self):
        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(bytes(self._test_task, 'UTF-8'))
        f.close()
        self.taskfile = f.name

        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(bytes(self.taskfile, 'UTF-8'))
        f.close()
        self.listfile = f.name

    def tearDown(self):
        os.remove(self.taskfile)
        os.remove(self.listfile)

    def test_local_retrieve_file(self):
        self.instance = LocalRetrieve(self.listfile)
        test_str = "/home/testuser/folder/folder/model.prototxt"
        ident = self.instance.retrieve_file(test_str)
        self.assertEqual(ident, test_str)

    def test_local_retrieve_task(self):
        self.instance = LocalRetrieve(self.listfile)
        for task in self.instance.retrieve_task():
            self.assertEqual(task['id'], '554d0b8888fce10300bf0bdf')
            self.assertEqual(len(task['directives']), 1)
Exemple #4
0
 def _gen_retrieve(self):
     """Create retrieve from config file"""
     # Retriever gets new Caffe tasks
     # If we don't want to override via solver get the specified retriever
     if not self.solver_override:
         logging.debug("Generating retriever specified in config file")
         retrieve_type = self._get_config('mri-client', 'retrieve').lower()
         if retrieve_type == 'local-retrieve':
             return LocalRetrieve(
                 self._get_config('local-retrieve', 'task_list'))
     # Otherwise we'll override by creating a false task list and false task (local)
     else:
         logging.debug("Overriding retriever via command line")
         return self._gen_false_local_retrieve()
 def test_local_retrieve_task(self):
     self.instance = LocalRetrieve(self.listfile)
     for task in self.instance.retrieve_task():
         self.assertEqual(task['id'], '554d0b8888fce10300bf0bdf')
         self.assertEqual(len(task['directives']), 1)
 def test_local_retrieve_file(self):
     self.instance = LocalRetrieve(self.listfile)
     test_str = "/home/testuser/folder/folder/model.prototxt"
     ident = self.instance.retrieve_file(test_str)
     self.assertEqual(ident, test_str)
 def test_local_retrieve_task(self):
     self.instance = LocalRetrieve(self.listfile)
     for task in self.instance.retrieve_task():
         self.assertEqual(task['id'], '554d0b8888fce10300bf0bdf')
         self.assertEqual(len(task['directives']), 1)
 def test_local_retrieve_file(self):
     self.instance = LocalRetrieve(self.listfile)
     test_str = "/home/testuser/folder/folder/model.prototxt"
     ident = self.instance.retrieve_file(test_str)
     self.assertEqual(ident, test_str)