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

NONE: fix a bug of the memory checking #452

Merged
merged 2 commits into from
Jun 18, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 6.4.1 / 2019-06-18

- [#452](https://github.com/kmyk/online-judge-tools/pull/452) fix a bug of the MLE-checking and RE

## 6.4.0 / 2019-06-16

- [#438](https://github.com/kmyk/online-judge-tools/pull/438) update `setup.cfg` to make `oj.exe` in Windows environments
Expand Down
2 changes: 1 addition & 1 deletion onlinejudge/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
__email__ = '[email protected]'
__license__ = 'MIT License'
__url__ = 'https://github.com/kmyk/online-judge-tools'
__version_info__ = (6, 4, 0, 'final', 0)
__version_info__ = (6, 4, 1, 'final', 0)
__version__ = '.'.join(map(str, __version_info__[:3]))
__description__ = 'Tools for online-judge services'
4 changes: 2 additions & 2 deletions onlinejudge/_implementation/command/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ def test_single_case(test_name: str, test_input_path: pathlib.Path, test_output_
def check_gnu_time(gnu_time: str) -> bool:
try:
with tempfile.NamedTemporaryFile(delete=True) as fh:
proc = subprocess.run([gnu_time, '-f', '%M KB', '-o', fh.name, '--quiet', '--', 'true'])
proc = subprocess.run([gnu_time, '-f', '%M KB', '-o', fh.name, '--', 'true'])
assert proc.returncode == 0
with open(fh.name) as fh1:
data = fh1.read()
int(utils.remove_suffix(data.rstrip(), ' KB'))
int(utils.remove_suffix(data.rstrip().splitlines()[-1], ' KB'))
return True
except NameError:
raise # NameError is not a runtime error caused by the environmet, but a coding mistake
Expand Down
4 changes: 2 additions & 2 deletions onlinejudge/_implementation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def exec_command(command_str: str, *, stdin: IO[Any], timeout: Optional[float] =
with context as fh:
command = shlex.split(command_str)
if gnu_time is not None:
command = [gnu_time, '-f', '%M', '-o', fh.name, '--quiet', '--'] + command
command = [gnu_time, '-f', '%M', '-o', fh.name, '--'] + command
begin = time.perf_counter()

try:
Expand All @@ -163,7 +163,7 @@ def exec_command(command_str: str, *, stdin: IO[Any], timeout: Optional[float] =
end = time.perf_counter()
if gnu_time is not None:
with open(fh.name) as fh1:
memory = int(fh1.read()) / 1000 # type: Optional[float]
memory = int(fh1.read().rstrip().splitlines()[-1]) / 1000 # type: Optional[float]
else:
memory = None
info = {
Expand Down
65 changes: 65 additions & 0 deletions tests/command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,68 @@ def test_call_test_small_memory(self):
for case in data:
self.assertEqual(case['status'], 'AC')
self.assertLess(case['memory'], 100)

def test_call_stderr(self):
data = self.snippet_call_test(
args=['-c', """bash -c 'echo foo >&2'"""],
files=[
{
'path': 'test/sample-1.in',
'data': 'foo\n'
},
],
expected=[{
'status': 'AC',
'testcase': {
'name': 'sample-1',
'input': '%s/test/sample-1.in',
},
'output': '',
'exitcode': 0,
}],
)

def test_call_runtime_error(self):
data = self.snippet_call_test(
args=['-c', 'false'],
files=[
{
'path': 'test/sample-1.in',
'data': 'foo\n'
},
],
expected=[{
'status': 'RE',
'testcase': {
'name': 'sample-1',
'input': '%s/test/sample-1.in',
},
'output': '',
'exitcode': 1,
}],
)

def test_call_stderr_and_fail(self):
data = self.snippet_call_test(
args=['-c', """perl -e 'die "good bye"'"""],
files=[
{
'path': 'test/sample-1.in',
'data': 'foo\n'
},
{
'path': 'test/sample-1.out',
'data': 'foo\n'
},
],
expected=[{
'status': 'WA',
'testcase': {
'name': 'sample-1',
'input': '%s/test/sample-1.in',
'output': '%s/test/sample-1.out',
},
'output': '',
'exitcode': 255,
}],
)