Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

Fixed extension test skipping #31

Merged
merged 2 commits into from
Nov 22, 2017
Merged
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
21 changes: 13 additions & 8 deletions ifj2017/test/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def load_section_dirs(self):
def load_tests(self, section_dir):
assert path.isdir(section_dir)

compact_tests = self._load_compact_tests(section_dir)
json_file = self._load_json_file(section_dir)
compact_tests = self._load_compact_tests(section_dir, json_file)
already_loaded = set(map(attrgetter('name'), compact_tests))
file_tests = self._load_file_tests(section_dir, already_loaded)
file_tests = self._load_file_tests(section_dir, already_loaded, json_file)
tests = tuple(file_tests) + tuple(compact_tests)
test_names = tuple(map(attrgetter('name'), tests))
conflicting = set(test for test in test_names if test_names.count(test) > 1)
Expand All @@ -42,20 +43,23 @@ def load_tests(self, section_dir):
key=lambda test: (len(test.name), test.name)
)

def _load_compact_tests(self, section_dir):
def _load_json_file(self, section_dir):
data = self.load_file(
path.join(section_dir, 'tests.json'),
allow_fail=True
)
if not data:
return ()
return {}
try:
data = json.loads(data)
return json.loads(data)
except (json.JSONDecodeError, TypeError) as e:
TestLogger.log_warning(
"File {} is not valid json to load ({}).".format(path.join(section_dir, 'tests.json'), e)
)
return ()
return {}
return data

def _load_compact_tests(self, section_dir, data):
cases = []
extensions = tuple(data.get('extensions', ()))
try:
Expand Down Expand Up @@ -102,7 +106,8 @@ def _load_compact_tests(self, section_dir):
return ()
return cases

def _load_file_tests(self, section_dir, already_loaded):
def _load_file_tests(self, section_dir, already_loaded, data):
extensions = tuple(data.get('extensions', ()))
for code_file in sorted(iglob(path.join(section_dir, "*.code"))):
name, _ = path.splitext(path.basename(code_file))
if name in already_loaded:
Expand All @@ -118,7 +123,7 @@ def _load_file_tests(self, section_dir, already_loaded):
int(self._load_test_file(section_dir, name, 'iexitcode') or 0),
self._load_test_file(section_dir, name, 'info') or self._get_code_info(code) or '',
section_dir,
set(),
set(extensions),
self._default_timeout
)
except ValueError as e:
Expand Down
4 changes: 2 additions & 2 deletions ifj2017/tests/02_functions/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
{
"info": "Asc value",
"stdout": " 104",
"code": "scope \n print asc(!\"ahoj\", 2); \n end scope"
"code": "scope \n dim a as integer \n a = asc(!\"ahoj\", 2) \n print a; \n end scope"
},
{
"info": "Chr function",
"stdout": "a",
"code": "scope \n print chr(97); \n end scope"
"code": "scope \n dim c as string \n c = chr(97) \n print c; \n end scope"
},
{
"info": "function integer implicit return",
Expand Down
11 changes: 10 additions & 1 deletion ifj2017/tests/05_conditions/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
},
{
"name": "04",
"stdout": " 123 74"
"stdout": " 123 74",
"extensions": [
"IFTHEN"
]
},
{
"name": "05",
Expand Down Expand Up @@ -57,6 +60,12 @@
"name": "13",
"stdout": "? ? 42",
"stdin": "Ahojky\nAhojky"
},
{
"name": "14",
"extensions": [
"IFTHEN"
]
}
]
}