Пример #1
0
    def setUp(self) -> None:
        lightly.api.api_workflow_client.__version__ = lightly.__version__
        warnings.filterwarnings("ignore", category=UserWarning)
        self.api_workflow_client = MockedApiWorkflowClient(token="token_xyz")

        self.valid_tag_name = self.api_workflow_client.get_all_tags()[0].name
        self.invalid_tag_name = "invalid_tag_name_xyz"
        self.valid_tag_id = self.api_workflow_client.get_all_tags()[0].id
        self.invalid_tag_id = "invalid-tag_id_xyz"
Пример #2
0
 def test_reorder_manual(self):
     filenames_on_server = ['a', 'b', 'c']
     api_workflow_client = MockedApiWorkflowClient(
         token="token_xyz", dataset_id="dataset_id_xyz")
     api_workflow_client.mappings_api.sample_names = filenames_on_server
     filenames_for_list = ['c', 'a']
     list_to_order = ['cccc', 'aaaa']
     list_ordered = api_workflow_client._order_list_by_filenames(
         filenames_for_list, list_to_order=list_to_order)
     list_desired_order = ['aaaa', 'cccc']
     assert list_ordered == list_desired_order
Пример #3
0
    def test_reorder_random(self):
        no_random_tries = 100
        for iter in range(no_random_tries):
            numbers_to_choose_from = list(range(100))
            numbers_all = list(np.random.choice(numbers_to_choose_from, 100))
            filenames_on_server = [f"img_{i}" for i in numbers_all]

            api_workflow_client = MockedApiWorkflowClient(
                token="token_xyz", dataset_id="dataset_id_xyz")
            api_workflow_client.mappings_api.sample_names = filenames_on_server

            numbers_in_tag = list(np.random.choice(numbers_to_choose_from, 50))
            filenames_for_list = [f"img_{i}" for i in numbers_in_tag]

            list_ordered = api_workflow_client._order_list_by_filenames(
                filenames_for_list, list_to_order=numbers_in_tag)
            list_desired_order = [
                i for i in numbers_all if i in numbers_in_tag
            ]
            assert list_ordered == list_desired_order
Пример #4
0
    def test_reorder_wrong_lengths(self):
        filenames_on_server = ['a', 'b', 'c']
        api_workflow_client = MockedApiWorkflowClient(
            token="token_xyz", dataset_id="dataset_id_xyz")
        api_workflow_client._mappings_api.sample_names = filenames_on_server
        filenames_for_list = ['c', 'a', 'b']
        list_to_order = ['cccc', 'aaaa', 'bbbb']

        with self.subTest("filenames_for_list wrong length"):
            with self.assertRaises(ValueError):
                api_workflow_client._order_list_by_filenames(
                    filenames_for_list[:-1], list_to_order)

        with self.subTest("list_to_order wrong length"):
            with self.assertRaises(ValueError):
                api_workflow_client._order_list_by_filenames(
                    filenames_for_list, list_to_order[:-1])

        with self.subTest("filenames_for_list and list_to_order wrong length"):
            with self.assertRaises(ValueError):
                api_workflow_client._order_list_by_filenames(
                    filenames_for_list[:-1], list_to_order[:-1])
Пример #5
0
class TestApiWorkflowTags(MockedApiWorkflowSetup):
    def setUp(self) -> None:
        lightly.api.api_workflow_client.__version__ = lightly.__version__
        warnings.filterwarnings("ignore", category=UserWarning)
        self.api_workflow_client = MockedApiWorkflowClient(token="token_xyz")

        self.valid_tag_name = self.api_workflow_client.get_all_tags()[0].name
        self.invalid_tag_name = "invalid_tag_name_xyz"
        self.valid_tag_id = self.api_workflow_client.get_all_tags()[0].id
        self.invalid_tag_id = "invalid-tag_id_xyz"

    def tearDown(self) -> None:
        warnings.resetwarnings()

    def test_get_all_tags(self):
        self.api_workflow_client.get_all_tags()

    def test_get_tag_name(self):
        self.api_workflow_client.get_tag_by_name(tag_name=self.valid_tag_name)

    def test_get_tag_name_nonexisting(self):
        with self.assertRaises(ValueError):
            self.api_workflow_client.get_tag_by_name(
                tag_name=self.invalid_tag_name)

    def test_get_tag_id(self):
        self.api_workflow_client.get_tag_by_id(tag_id=self.valid_tag_id)

    def test_get_filenames_in_tag(self):
        tag_data = self.api_workflow_client.get_tag_by_name(
            tag_name=self.valid_tag_name)
        self.api_workflow_client.get_filenames_in_tag(tag_data)

    def test_get_filenames_in_tag_with_filenames(self):
        tag_data = self.api_workflow_client.get_tag_by_name(
            tag_name=self.valid_tag_name)
        filenames = self.api_workflow_client.get_filenames()
        self.api_workflow_client.get_filenames_in_tag(tag_data, filenames)

    def test_get_filenames_in_tag_exclude_parent(self):
        tag_data = self.api_workflow_client.get_tag_by_name(
            tag_name=self.valid_tag_name)
        self.api_workflow_client.get_filenames_in_tag(tag_data,
                                                      exclude_parent_tag=True)

    def test_get_filenames_in_tag_with_filenames_exclude_parent(self):
        tag_data = self.api_workflow_client.get_tag_by_name(
            tag_name=self.valid_tag_name)
        filenames = self.api_workflow_client.get_filenames()
        self.api_workflow_client.get_filenames_in_tag(tag_data,
                                                      filenames,
                                                      exclude_parent_tag=True)

    def test_create_tag_from_filenames(self):
        filenames_server = self.api_workflow_client.get_filenames()
        filenames_new_tag = filenames_server[:10][::3]
        self.api_workflow_client.create_tag_from_filenames(
            filenames_new_tag, new_tag_name="funny_new_tag")

    def test_create_tag_from_filenames(self):
        filenames_server = self.api_workflow_client.get_filenames()
        filenames_new_tag = filenames_server[:10][::3]
        filenames_new_tag[0] = 'some-random-non-existing-filename.jpg'
        with self.assertRaises(RuntimeError):
            self.api_workflow_client.create_tag_from_filenames(
                filenames_new_tag, new_tag_name="funny_new_tag")
Пример #6
0
 def test_error_if_version_is_incompatible(self):
     lightly.api.api_workflow_client.__version__ = "0.0.0"
     with self.assertRaises(ValueError):
         MockedApiWorkflowClient(token="token_xyz")
     lightly.api.api_workflow_client.__version__ = lightly.__version__
Пример #7
0
 def setUp(self) -> None:
     lightly.api.api_workflow_client.__version__ = lightly.__version__
     self.api_workflow_client = MockedApiWorkflowClient(token="token_xyz")