Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STCC-309 Refactor common_testing.py [TN] #226

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/scratchtocatrobat/tools/common_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
TEST_PROJECT_URL_TO_ID_MAP = {
# These projects are all Scratch3 projects now.
'https://scratch.mit.edu/projects/390299427/': '390299427', # dance back
# FIXME: fails with error 'http://scratch.mit.edu/projects/10189712/': '10189712', # kick the ball
'https://scratch.mit.edu/projects/10189712/': '10189712', # kick the ball
'https://scratch.mit.edu/projects/390300019/': '390300019', # dancing in the castle
'https://scratch.mit.edu/projects/390300135/': '390300135', # cat has message
'https://scratch.mit.edu/projects/390300261/': '390300261', # jai ho!
'https://scratch.mit.edu/projects/390300374/': '390300374', # simple memory
'https://scratch.mit.edu/projects/390300542/': '390300542', # same image, different objects
'https://scratch.mit.edu/projects/390300374/': '390300374', # simple memory
'https://scratch.mit.edu/projects/390300542/': '390300542', # same image, different objects
}
TEST_PROJECT_FILENAME_TO_ID_MAP = {
'dancing_castle.zip': '390300019',
Expand Down Expand Up @@ -153,6 +153,11 @@ def __assertTagsAreNonEmpty(self, xml_root):
except:
self.fail("Expection '{}' with url '{}'".format(sys.exc_info()[0], xml_node.text))

def assertSoundAndLookProgramStructure(self, file_names, directory):
for node in file_names:
path = os.path.join(directory, node.text)
assert os.path.exists(path), "Missing: {}, available files: {}".format(repr(path), os.listdir(os.path.dirname(path)))

def assertValidCatrobatProgramStructure(self, project_path, project_name):
project_xml_path = os.path.join(project_path, catrobat.PROGRAM_SOURCE_FILE_NAME)
with open(project_xml_path) as fp:
Expand All @@ -168,16 +173,11 @@ def assertValidCatrobatProgramStructure(self, project_path, project_name):
catrobat_version_from_xml = root.find("header/catrobatLanguageVersion")
assert float(catrobat_version_from_xml.text) > 0.0

# TODO: refactor duplication
sounds_dir = converter.ConvertedProject._sounds_dir_of_project(project_path)
for node in root.findall('.//sound/fileName'):
sound_path = os.path.join(sounds_dir, node.text)
assert os.path.exists(sound_path)
self.assertSoundAndLookProgramStructure(root.findall('.//sound/fileName'), sounds_dir)

images_dir = converter.ConvertedProject._images_dir_of_project(project_path)
for node in root.findall('.//look/fileName'):
image_path = os.path.join(images_dir, node.text)
assert os.path.exists(image_path), "Missing: {}, available files: {}".format(repr(image_path), os.listdir(os.path.dirname(image_path)))
self.assertSoundAndLookProgramStructure(root.findall('.//look/fileName'), images_dir)

def assertValidCatrobatProgramPackageAndUnpackIf(self, zip_path, project_name, unused_scratch_resources=None):
if unused_scratch_resources is None:
Expand Down