Exemple #1
0
 def model_file(self, key: str) -> ModelFile:
     """
     Provides access to a ModelFile, which can be used to store models that should be transferred between
     different stations
     """
     if key not in self._model_files.keys():
         self._model_files[key] = ModelFile(key)
     return self._model_files[key]
Exemple #2
0
 def setUp(self):
     self.maxDiff = None
     self.response1 = RunResponse(run_exit=AlgorithmFailureRunExit('foo'),
                                  free_text_message='bar',
                                  rebase=DockerRebaseStrategy(
                                      frm='frm',
                                      next_train_tags=['tag1', 'tag2'],
                                      export_files=[]))
     self.response2 = RunResponse(run_exit=AlgorithmFailureRunExit('bar'),
                                  free_text_message='Some text',
                                  rebase=DockerRebaseStrategy(
                                      frm='some remote Docker repository',
                                      next_train_tags=[],
                                      export_files=[
                                          ModelFile('key1'),
                                          ModelFile('key2'),
                                          AlgorithmFile('key3')
                                      ]))
 def setUp(self):
     self.model_file1 = ModelFile('foo')
     self.model_file2 = ModelFile('bar')
class ModelFileTests(BaseTest):
    def setUp(self):
        self.model_file1 = ModelFile('foo')
        self.model_file2 = ModelFile('bar')

    ###########################################
    # Invalid Model key names
    ###########################################
    def test_invalid_key_1(self):
        self.assertValueError(lambda: ModelFile(''))

    def test_invalid_key_2(self):
        self.assertValueError(lambda: ModelFile('foo/bar'))

    ###########################################
    # Invalid Model key names
    ###########################################
    def test_eq_1(self):
        self.assertIsEqual(self.model_file1, ModelFile('foo'))

    def test_eq_2(self):
        self.assertIsEqual(self.model_file2, ModelFile('bar'))

    def test_unequal(self):
        self.assertNotEqual(self.model_file1, self.model_file2)

    ###########################################
    # Type
    ###########################################
    def test_type_1(self):
        self.checkExpect(expect=['ModelFile', 'TrainFile'],
                         actual=self.model_file1.type)

    def test_type_2(self):
        self.checkExpect(expect=['ModelFile', 'TrainFile'],
                         actual=self.model_file2.type)

    ###########################################
    # Display
    ###########################################
    def test_display_1(self):
        self.checkExpect(expect='ModelFile', actual=self.model_file1.type_name)

    def test_display_2(self):
        self.checkExpect(expect='ModelFile', actual=self.model_file2.type_name)

    ###########################################
    # Data
    ###########################################
    def test_data_1(self):
        self.checkExpect(
            expect={'absolutePhysicalPath': '/opt/pht_train/model/foo'},
            actual=self.model_file1.data)

    def test_data_2(self):
        self.checkExpect(
            expect={'absolutePhysicalPath': '/opt/pht_train/model/bar'},
            actual=self.model_file2.data)

    ###########################################
    # as dict
    ###########################################
    def test_as_dict_1(self):
        self.checkMapping(expect={
            'absolutePhysicalPath': '/opt/pht_train/model/foo',
            '@type': ['ModelFile', 'TrainFile'],
            '@typeName': 'ModelFile',
            "@typeSystem": {
                'name': 'pythonclass',
                'version': '1.0'
            },
        },
                          actual=self.model_file1.as_simple_mapping())

    def test_as_dict_2(self):
        self.checkMapping(expect={
            'absolutePhysicalPath': '/opt/pht_train/model/bar',
            '@type': ['ModelFile', 'TrainFile'],
            '@typeName': 'ModelFile',
            "@typeSystem": {
                'name': 'pythonclass',
                'version': '1.0'
            },
        },
                          actual=self.model_file2.as_simple_mapping())

    ###########################################
    # absolute path
    ###########################################
    def test_absolute_path_1(self):
        self.checkExpect(expect='/opt/pht_train/model/foo',
                         actual=self.model_file1.absolute_physical_path)

    def test_absolute_path_2(self):
        self.checkExpect(expect='/opt/pht_train/model/bar',
                         actual=self.model_file2.absolute_physical_path)

    ###########################################
    # total ordering
    ###########################################
    def test_ordering_1(self):
        self.assertLess(self.model_file2, self.model_file1)

    def test_ordering_2(self):
        self.assertLessEqual(self.model_file2, self.model_file1)

    def test_ordering_3(self):
        self.assertGreater(self.model_file1, self.model_file2)

    def test_ordering_4(self):
        self.assertGreaterEqual(self.model_file1, self.model_file2)
 def test_eq_2(self):
     self.assertIsEqual(self.model_file2, ModelFile('bar'))
 def test_eq_1(self):
     self.assertIsEqual(self.model_file1, ModelFile('foo'))
 def test_invalid_key_2(self):
     self.assertValueError(lambda: ModelFile('foo/bar'))
 def test_invalid_key_1(self):
     self.assertValueError(lambda: ModelFile(''))
Exemple #9
0
 def __init__(self):
     self._model_files = {}
     # Directories for the train cargo are created upon Train instantiation
     os.makedirs(AlgorithmFile.base_dir(), exist_ok=True)
     os.makedirs(ModelFile.base_dir(), exist_ok=True)
class TrainFileTests(BaseTest):
    def setUp(self):
        self.modelfile1 = ModelFile('foo')
        self.modelfile2 = ModelFile('bar')

    ########################################################
    # Value Error
    ########################################################
    def test_value_error_1(self):
        self.assertValueError(lambda: ModelFile(''))

    def test_value_error_2(self):
        self.assertValueError(lambda: ModelFile(' '))

    def test_value_error_3(self):
        self.assertValueError(lambda: ModelFile('foo/bar'))

    def test_value_error_4(self):
        self.assertValueError(lambda: ModelFile('foo\\bar'))

    ########################################################
    # eq
    ########################################################
    def test_eq_1(self):
        self.assertIsEqual(self.modelfile1, ModelFile('foo'))

    def test_eq_2(self):
        self.assertIsEqual(self.modelfile2, ModelFile('bar'))

    ########################################################
    # path
    ########################################################
    def test_path_1(self):
        self.checkExpect(expect='/opt/pht_train/model/foo',
                         actual=self.modelfile1.absolute_physical_path)

    def test_path_2(self):
        self.checkExpect(expect='/opt/pht_train/model/bar',
                         actual=self.modelfile2.absolute_physical_path)

    ########################################################
    # type
    ########################################################
    def test_type_1(self):
        self.checkExpect(expect=['ModelFile', 'TrainFile'],
                         actual=self.modelfile1.type)

    def test_type_2(self):
        self.checkExpect(expect=['ModelFile', 'TrainFile'],
                         actual=self.modelfile2.type)

    ########################################################
    # display
    ########################################################
    def test_type_name_1(self):
        self.checkExpect(expect='ModelFile', actual=self.modelfile1.type_name)

    def test_type_name_2(self):
        self.checkExpect(expect='ModelFile', actual=self.modelfile2.type_name)

    ########################################################
    # data
    ########################################################
    def test_data_1(self):
        self.checkExpect(
            expect={'absolutePhysicalPath': '/opt/pht_train/model/foo'},
            actual=self.modelfile1.data)

    def test_data_2(self):
        self.checkMapping(
            expect={'absolutePhysicalPath': '/opt/pht_train/model/bar'},
            actual=self.modelfile2.data)

    ########################################################
    # as_dict
    ########################################################
    def test_as_simple_dict_1(self):
        self.checkExpect(expect={
            'absolutePhysicalPath': '/opt/pht_train/model/foo',
            '@type': ['ModelFile', 'TrainFile'],
            '@typeName': 'ModelFile',
            '@typeSystem': {
                'name': 'pythonclass',
                'version': '1.0'
            }
        },
                         actual=self.modelfile1.as_simple_mapping())

    def test_as_simple_dict_2(self):
        self.checkExpect(expect={
            'absolutePhysicalPath': '/opt/pht_train/model/bar',
            '@type': ['ModelFile', 'TrainFile'],
            '@typeName': 'ModelFile',
            '@typeSystem': {
                'name': 'pythonclass',
                'version': '1.0'
            }
        },
                         actual=self.modelfile2.as_simple_mapping())
 def test_value_error_4(self):
     self.assertValueError(lambda: ModelFile('foo\\bar'))
 def test_value_error_2(self):
     self.assertValueError(lambda: ModelFile(' '))