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-293] Refactor Blockmapping.py #225

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
32 changes: 29 additions & 3 deletions run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import atexit
import os
import platform
import subprocess
import sys

sys.path.append(os.path.join(os.path.realpath(os.path.dirname(__file__)), "src"))
from scratchtocatrobat.tools import helpers

Expand All @@ -37,6 +39,9 @@ helpers.make_dir_if_not_exists(data_dirs)
env = os.environ
env['JYTHONPATH'] = jython_path if sys.platform != 'win32' else jython_path.replace(":", ";")

test_folder_path = 'test/res/scratch'
if not os.path.exists(test_folder_path):
helpers.error("Test folder does not exist")
if not os.path.isdir(jython_home_dir):
helpers.error("Invalid jython home path given. No valid directory. Please update 'jython_home' in the config file.")
if not os.path.isfile(jython_exec_path):
Expand All @@ -55,6 +60,27 @@ for subdir, dirs, files in os.walk(helpers.SRC_PATH):
test_module_name = relative_subdir_path.replace(os.sep, ".") + "." + file
modules_under_test.add(test_module_name)

# checking all existing files
files_in_test_folders = list()
for subdir, dirs, files in os.walk(test_folder_path):
for file in files:
files_in_test_folders.append(subdir + "/" + file)


# deleting all generated files
def delete_files():
print("-" * 80)
print("Deleting all test generated files")
print()
for subdir, dirs, files in os.walk(test_folder_path):
for file in files:
if not files_in_test_folders.__contains__(subdir + "/" + file):
print("Deleting: " + subdir + "/" + file)
os.remove(subdir + "/" + file)


atexit.register(delete_files)

if len(sys.argv) >= 2 and sys.argv[1] != "all":
if (isinstance(sys.argv[1], str) or isinstance(sys.argv[1], unicode)) and sys.argv[1].startswith("test_"):
argument = sys.argv[1] if sys.argv[1].endswith('.py') else sys.argv[1] + ".py"
Expand All @@ -67,9 +93,9 @@ else:
print("Testing all modules!")

for module in modules_under_test:
print("-"*80)
print("-" * 80)
print("Testing '%s':" % module)
print("-"*80)
print("-" * 80)
exec_args = [jython_exec_path, "-m", module[:-3]]

if len(sys.argv) >= 3:
Expand Down
7 changes: 5 additions & 2 deletions src/scratchtocatrobat/scratch/scratch3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@


from scratchtocatrobat.tools import logger, helpers
from scratchtocatrobat.scratch.scratch3visitor.scratch2_json_format import Scratch3_2Opcodes as opcodes
import os
import json

Expand Down Expand Up @@ -164,7 +167,7 @@ def parse_monitor(monitor):
}
else:
#sb3 has same opcode for background # and name, sb2 has two different opcodes => decide opcode depending on param
if monitor["opcode"] == "looks_backdropnumbername":
if monitor["opcode"] == opcodes.LOOKS_BACK_DROP_NUMBER_NAME:
if monitor.get("params", {}).get("NUMBER_NAME") == "name":
monitor["opcode"] = "looks_backdropname"
else:
Expand All @@ -175,7 +178,7 @@ def parse_monitor(monitor):
return None
target = monitor.get("spriteName", None)
param = (MONITOR_PARAM_MAPPING[monitor["opcode"]](monitor["params"]) if monitor["opcode"] in MONITOR_PARAM_MAPPING else None)
if monitor["opcode"] in ["data_variable", "sensing_current"]:
if monitor["opcode"] in ["data_variable", opcodes.SENSING_CURRENT]:
label = param
else:
label = MONITOR_LABEL_MAPPING[monitor["opcode"]]
Expand Down
Loading