Ejemplo n.º 1
0
    def assertMainSuccess(self, args, project_id):
        output_path = self._testresult_folder_path
        if len(args) == 1:
            args += [output_path]
        return_val = self.execute_run_script(args)
        assert return_val == main.EXIT_SUCCESS

        project_name = scratchwebapi.request_project_name_for(project_id)
        self.assertValidCatrobatProgramPackageAndUnpackIf(converter.ConvertedProject._converted_output_path(output_path, project_name), project_name)
 def test_can_request_project_name_for_id(self):
     for project_id in common_testing.TEST_PROJECT_FILENAME_TO_ID_MAP.itervalues():
         # FIXME: compare with names
         assert scratchwebapi.request_project_name_for(project_id) is not None
Ejemplo n.º 3
0
    def __init__(self, project_base_path, name=None, id_=None):
        def read_md5_to_resource_path_mapping():
            md5_to_resource_path_map = {}
            # TODO: clarify that only files with extension are covered
            for project_file_path in glob.glob(os.path.join(project_base_path, "*.*")):
                resource_name = common.md5_hash(project_file_path) + os.path.splitext(project_file_path)[1]
                md5_to_resource_path_map[resource_name] = project_file_path
            try:
                # penLayer is no regular resource file
                del md5_to_resource_path_map[self['penLayerMD5']]
            except KeyError:
                # TODO: include penLayer download in webapi
                pass
            return md5_to_resource_path_map

        def verify_resources(resources):
            for res_dict in resources:
                assert JsonKeys.SOUND_MD5 in res_dict or JsonKeys.COSTUME_MD5 in res_dict
                md5_file = res_dict[JsonKeys.SOUND_MD5] if JsonKeys.SOUND_NAME in res_dict else res_dict[JsonKeys.COSTUME_MD5]
                resource_md5 = os.path.splitext(md5_file)[0]
                if md5_file not in self.md5_to_resource_path_map:
                    raise ProjectError("Missing resource file at project: {}. Provide resource with md5: {}".format(project_base_path, resource_md5))

        super(Project, self).__init__(self.raw_project_code_from_project_folder_path(project_base_path))
        self.project_base_path = project_base_path
        if id_ is not None:
            self.project_id = id_
        else:
            self.project_id = self.get_info().get("projectID")
        if not self.project_id:
            self.project_id = "0"
            name = "Testproject"
            #raise ProjectError("No project id specified in project file. Please provide project id with constructor.")
        if name is not None:
            self.name = name
            self.description = ""
        else:
            # FIXME: for some projects no project info available
            try:
                self.name = scratchwebapi.request_project_name_for(self.project_id)
                self.description = scratchwebapi.request_project_description_for(self.project_id)
            except urllib2.HTTPError:
                self.name = str(self.project_id)
                self.description = ""
        self.name = self.name.strip()
        self.md5_to_resource_path_map = read_md5_to_resource_path_mapping()
        assert self['penLayerMD5'] not in self.md5_to_resource_path_map
        for scratch_object in self.objects:
            # TODO: rename to verify_object?
            verify_resources(scratch_object.get_sounds() + scratch_object.get_costumes())

        self.global_user_lists = [scratch_obj.get_lists() for scratch_obj in self.objects if scratch_obj.is_stage()][0]

        listened_keys = []
        for scratch_obj in self.objects:
            for script in scratch_obj.scripts:
                if script.type == SCRIPT_KEY_PRESSED:
                    assert len(script.arguments) == 1
                    listened_keys += script.arguments
        self.listened_keys = set(listened_keys)
        # TODO: rename
        self.background_md5_names = set([costume[JsonKeys.COSTUME_MD5] for costume in self.get_costumes()])
        self.unused_resource_names, self.unused_resource_paths = common.pad(zip(*self.find_unused_resources_name_and_filepath()), 2, [])
        for unused_path in self.unused_resource_paths:
            _log.warning("Project folder contains unused resource file: '%s'. These will be omitted for Catrobat project.", os.path.basename(unused_path))