コード例 #1
0
    def test_get_from_class_error_not_class(self, mocked_import_custom_object):
        """Test to get a song class that is not a class
        """
        # mock the returned class
        mocked_import_custom_object.return_value = "str"

        # call the method
        with self.assertRaisesRegex(customization.InvalidObjectTypeError,
                                    "song.MySong is not a class"):
            customization.get_custom_song("song.MySong")
コード例 #2
0
    def test_get_from_module_error_not_class(self,
                                             mocked_import_custom_object):
        """Test to get a default song class that is not a class
        """
        # mock the returned class
        my_module = ModuleType("my_module")
        my_module.Song = 42
        mocked_import_custom_object.return_value = my_module

        # call the method
        with self.assertRaisesRegex(customization.InvalidObjectTypeError,
                                    "song.Song is not a class"):
            customization.get_custom_song("song")
コード例 #3
0
    def test_get_from_module_error_no_default(self,
                                              mocked_import_custom_object):
        """Test to get a default song class that does not exist
        """
        # mock the returned class
        my_module = ModuleType("my_module")
        mocked_import_custom_object.return_value = my_module

        # call the method
        with self.assertRaisesRegex(
                customization.InvalidObjectModuleNameError,
                "Cannot find default class Song in module my_module",
        ):
            customization.get_custom_song("song")
コード例 #4
0
    def test_get_from_class(self, mocked_import_custom_object):
        """Test to get a valid song class from class module name
        """

        # mock the returned class
        class MySong(BaseSong):
            pass

        mocked_import_custom_object.return_value = MySong

        # call the method
        with self.assertLogs("dakara_feeder.customization") as logger:
            CustomSong = customization.get_custom_song("song.MySong")

        # assert the result
        self.assertIs(CustomSong, MySong)

        # assert the call
        mocked_import_custom_object.assert_called_with("song.MySong")

        # assert logs
        self.assertListEqual(
            logger.output,
            [
                "INFO:dakara_feeder.customization:Using custom Song class: song.MySong"
            ],
        )
コード例 #5
0
    def load(self):
        """Execute side-effect initialization tasks
        """
        # check version
        check_version()

        # select song class
        if self.song_class_module_name:
            self.song_class = get_custom_song(self.song_class_module_name)

        # check directory exists
        self.check_kara_folder_path()

        # authenticate to server
        self.dakara_server.authenticate()
コード例 #6
0
    def test_get_from_module(self, mocked_import_custom_object):
        """Test to get a valid default song class from module name
        """
        # mock the returned class
        my_module = ModuleType("my_module")

        class Song(BaseSong):
            pass

        my_module.Song = Song
        mocked_import_custom_object.return_value = my_module

        # call the method
        CustomSong = customization.get_custom_song("song")

        # assert the result
        self.assertIs(CustomSong, Song)