def test_can_access_project_id(self): test_project_folder_to_project_id = { "dancing_castle": "10205819", } for project_folder, project_id in test_project_folder_to_project_id.iteritems(): project_path = common_testing.get_test_project_path(project_folder) assert project_id, scratch.Project(project_path).project_id
def test_can_convert_file_from_svg_to_png(self): regular_svg_path = os.path.join(common_testing.get_test_project_path("dancing_castle"), "1.svg") svg_path_with_fileext = os.path.join(self.temp_dir, "test_path_which_includes_extension_.svg.svg", "1.svg") os.makedirs(os.path.dirname(svg_path_with_fileext)) shutil.copy(regular_svg_path, svg_path_with_fileext) for input_svg_path in [regular_svg_path, svg_path_with_fileext]: assert os.path.exists(input_svg_path) output_png_path = svgtopng.convert(input_svg_path) assert os.path.exists(output_png_path) assert imghdr.what(output_png_path) == "png"
def _test_project(self, project_name): if os.path.splitext(project_name)[1]: tempdir = common.TemporaryDirectory() scratch_project_dir = tempdir.name self.addCleanup(tempdir.cleanup) common.extract(common_testing.get_test_project_packed_file(project_name), scratch_project_dir) else: scratch_project_dir = common_testing.get_test_project_path(project_name) scratch_project = scratch.Project(scratch_project_dir, name=project_name, id_=common_testing.PROJECT_DUMMY_ID) converted_project = converter.converted(scratch_project) catrobat_zip_file_name = converted_project.save_as_catrobat_package_to(self._testresult_folder_path) self.assertValidCatrobatProgramPackageAndUnpackIf(catrobat_zip_file_name, project_name, unused_scratch_resources=scratch_project.unused_resource_names) return converted_project.catrobat_program
from scratchtocatrobat import catrobat from scratchtocatrobat import common from scratchtocatrobat import common_testing from scratchtocatrobat import scratch from scratchtocatrobat import converter def create_catrobat_sprite_stub(): sprite = catbase.Sprite("Dummy") looks = sprite.getLookDataList() for lookname in ["look1", "look2", "look3"]: looks.add(catrobat.create_lookdata(lookname, None)) return sprite DUMMY_CATR_SPRITE = create_catrobat_sprite_stub() TEST_PROJECT_PATH = common_testing.get_test_project_path("dancing_castle") def _dummy_project(): return scratch.Project(TEST_PROJECT_PATH, name="dummy") # TODO: fix / reorganize test # # class TestConvertExampleProject(common_testing.ProjectTestCase): # # expected_sprite_names = ["Sprite1, Cassy Dance"] # expected_script_classes = [[catbase.StartScript, ], []] # expected_brick_classes = [[catbricks.WaitBrick, catbricks.RepeatBrick, catbricks.MoveNStepsBrick, catbricks.WaitBrick, catbricks.MoveNStepsBrick, catbricks.WaitBrick, catbricks.LoopEndBrick], []] # # def __init__(self, *args, **kwargs):
def test_can_access_unused_resources_of_project(self): project = scratch.Project(common_testing.get_test_project_path("simple"), name="simple", id_=common_testing.PROJECT_DUMMY_ID) assert len(project.unused_resource_paths) > 0 assert set(map(os.path.basename, project.unused_resource_paths)) == set(['0.png', '2.wav', '3.png', '4.png', '5.png', '6.png', '8.png'])
def test_can_access_listened_pressed_keys(self): project = scratch.Project(common_testing.get_test_project_path("keys_pressed")) assert project.listened_keys == set(["d", "c", "a", "4", "8"])
def setUp(self): self.project = scratch.Project(common_testing.get_test_project_path(self.project_folder))
def test_fail_on_project_with_missing_sound_files(self): with self.assertRaises(scratch.ProjectError): # TODO: check error type scratch.Project(common_testing.get_test_project_path("missing_image_resources"))
def test_fail_on_non_existing_input_path(self): with self.assertRaises(EnvironmentError): # TODO: check error message scratch.Project(common_testing.get_test_project_path("non_existing_path"))
def test_can_construct_on_correct_input(self): assert scratch.Project(common_testing.get_test_project_path("simple"), name="dummy", id_=common_testing.PROJECT_DUMMY_ID)
def setUp(self): unittest.TestCase.setUp(self) self.project = scratch.RawProject.from_project_folder_path(common_testing.get_test_project_path("dancing_castle"))
def test_fail_on_corrupt_file(self): with self.assertRaises((scratch.UnsupportedProjectFileError, scratch.ObjectError)): scratch.RawProject.from_project_folder_path(common_testing.get_test_project_path("faulty_json_file"))
def test_can_create_from_project_directory(self): for project_name in self.TEST_PROJECTS: assert scratch.RawProject.from_project_folder_path(common_testing.get_test_project_path(project_name))
def test_can_create_from_raw_content(self): for project_name in self.TEST_PROJECTS: project_data_path = os.path.join(common_testing.get_test_project_path(project_name), scratch._PROJECT_FILE_NAME) assert scratch.RawProject.from_project_code_content(common.content_of(project_data_path))