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

Commit b7cfe16

Browse files
committed
✨ Fix hiding test cases
1 parent 9777048 commit b7cfe16

4 files changed

Lines changed: 33 additions & 14 deletions

File tree

runestone/hparsons/hparsons.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ def setup(app):
4343
TEMPLATE_START = """
4444
<div>
4545
<div data-component="hparsons" id="%(divid)s" data-question_label="%(question_label)s" class="alert alert-warning hparsons" >
46-
<div>
46+
<div class="hparsons_question hparsons-text" >
4747
"""
4848

4949
TEMPLATE_END = """
5050
</div>
51-
<div class="hparsons_question hparsons-text" >%(problem)s</div>
52-
<div class="hparsons %(hidetests)s" %(textentry)s %(nostrictmatch)s>
51+
<div>%(instructions)s</div>
52+
<div class="hparsons" %(textentry)s %(nostrictmatch)s %(hidetests)s>
5353
<pre>%(settings)s</pre>
5454
</div>
5555
</div>
@@ -147,7 +147,7 @@ def run(self):
147147
else:
148148
self.options['textentry'] = ''
149149
if "hidetests" in self.options:
150-
self.options['hidetests'] = 'hidetests'
150+
self.options['hidetests'] = ' data-hidetests="true"'
151151
else:
152152
self.options['hidetests'] = ''
153153
if "nostrictmatch" in self.options:
@@ -167,7 +167,7 @@ def run(self):
167167
has_content = True
168168
delimitiers_index[i] = self.content.index(delimitiers[i])
169169
if has_content:
170-
sorted_index, sorted_delimiters = [list(t) for t in zip(*[pair for pair in sorted(zip(delimitiers_index, delimitiers)) if pair[0] > 0])]
170+
sorted_index, sorted_delimiters = [list(t) for t in zip(*[pair for pair in sorted(zip(delimitiers_index, delimitiers)) if pair[0] >= 0])]
171171
else:
172172
sorted_index = []
173173
sorted_delimiters = []
@@ -178,9 +178,9 @@ def run(self):
178178

179179
if '--problem--' in sorted_delimiters:
180180
index = sorted_delimiters.index('--problem--')
181-
self.options['problem'] = '\n'.join(content[(sorted_index[index] + 1): (sorted_index[index + 1] if index + 1 < len(sorted_index) else len(content))])
181+
self.options['instructions'] = '\n'.join(content[(sorted_index[index] + 1): (sorted_index[index + 1] if index + 1 < len(sorted_index) else len(content))])
182182
else:
183-
self.options['problem'] = 'empty problem'
183+
self.options['instructions'] = 'empty problem'
184184

185185
if '--blocks--' in sorted_delimiters:
186186
index = sorted_delimiters.index('--blocks--')
@@ -224,12 +224,13 @@ def run(self):
224224

225225
# exist in short answer and mchoice but not parsons
226226
# For MChoice its better to insert the qnum into the content before further processing.
227-
self.updateContent()
227+
# self.updateContent()
228228

229+
# TODO: fix the nested parse
229230
# same as mchoice, different from parsons. i think it is for generating instructions.
230231
# parsons:
231232
# self.state.nested_parse(
232-
# self.options["instructions"], self.content_offset, parsons_node
233+
# self.options['instructions'], self.content_offset, hparsons_node
233234
# )
234235

235236

runestone/hparsons/js/hparsons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default class HParsons extends RunestoneBase {
6060
console.log($(this.origElem).data("textentry"))
6161
let settings = JSON.parse($(this.origElem).children()[0].innerText)
6262
attributes += ' input-type=' + ($(this.origElem).data("textentry") ? 'text' : 'parsons' );
63+
attributes += $(this.origElem).data("hidetests") ? ' hidetests="true"': '';
6364
$(this.origElem).html('<regex-element' + attributes + '></regex-element>');
6465
let regexElement = $(this.origElem).children()[0];
6566
if ($(this.origElem).data("nostrictmatch")) {

runestone/hparsons/js/regex-element.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15913,8 +15913,14 @@ class UnitTestTable {
1591315913
this.el = document.createElement('div');
1591415914
this.el.id = 'regextool-' + this.parentElement.toolNumber + '-unittest-table';
1591515915
this.el.classList.add('regex-unittest');
15916+
if (this.parentElement.getAttribute('hidetests')) {
15917+
this.el.style.display = 'none';
15918+
}
15919+
else {
15920+
this.el.style.display = 'block';
15921+
}
1591615922
// the element is hidden initially.
15917-
this.el.classList.add('collapse');
15923+
// this.el.classList.add('collapse');
1591815924
// columns enabled besides the status column
1591915925
// TODO: only enabled notes for study 0 and 1
1592015926
this.columnsEnabled = ['actualOutput', 'expectedOutput', 'input', 'notes'];
@@ -16015,7 +16021,7 @@ class UnitTestTable {
1601516021
// creating the status(the first) column
1601616022
const row = document.createElement('tr');
1601716023
let status = result.success ? (JSON.stringify(result.match) === JSON.stringify(testCase.expect) ? 'Pass' : 'Fail') : 'Error';
16018-
console.log(status);
16024+
// console.log(status)
1601916025
// if (status == 'Pass' && JSON.stringify(testCase.expect) != '[]' && this.noGroupsAllowed && window.pyodide.globals.unit_match_group_cnt != 1) {
1602016026
// status = 'Fail'
1602116027
// // fail because no group is allowed
@@ -16813,7 +16819,7 @@ class RegexElement extends HTMLElement {
1681316819
};
1681416820
this.logEvent(problemFinished);
1681516821
};
16816-
static get observedAttributes() { return ['input-type', 'problem-id']; }
16822+
static get observedAttributes() { return ['input-type', 'problem-id', 'hidetests']; }
1681716823
attributeChangedCallback(name, oldValue, newValue) {
1681816824
switch (name) {
1681916825
case 'input-type': {
@@ -16824,6 +16830,14 @@ class RegexElement extends HTMLElement {
1682416830
this.problemId = newValue;
1682516831
break;
1682616832
}
16833+
case 'hidetests': {
16834+
if (newValue) {
16835+
this.unitTestTable.el.style.display = 'none';
16836+
}
16837+
else {
16838+
this.unitTestTable.el.style.display = 'block';
16839+
}
16840+
}
1682716841
}
1682816842
}
1682916843
initRegexInput(inputDiv) {

runestone/hparsons/test/_sources/index.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ Horizontal Parsons + Regex
88
---------------------------
99

1010
.. hparsons:: codeexample1
11-
:hidetests:
1211
:nostrictmatch:
1312

1413
--problem--
15-
Capture words that start with a vowel letter(aeiou), but ends with a non-vowel letter. There can be 0 or more letters in between. Also, it is not allowed to have other characters besides letter in between. e.g. your regular expression should match unicorn, element, but should not match: banana, apple. All letters are lowercase.
14+
Capture words that start with a vowel letter(aeiou), but ends with a non-vowel letter.
15+
There can be 0 or more letters in between.
16+
Also, it is not allowed to have other characters besides letter in between.
17+
e.g. your regular expression should match unicorn, element, but should not match: banana, apple. All letters are lowercase.
1618
--blocks--
1719
[a-z]
1820
[aeiou]
@@ -54,6 +56,7 @@ Horizontal Parsons + Regex
5456

5557
.. hparsons:: codeexample2
5658
:textentry:
59+
:hidetests:
5760

5861
content content content
5962

0 commit comments

Comments
 (0)