Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Apr 4, 2024
1 parent fbffbda commit 3b4bd7f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/commands/export/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,30 @@ def test_no_ocen(create_package):
with tarfile.open(f'{task_id}.tgz', "r") as tar:
sinol_util.extract_tar(tar, tmpdir)
assert not os.path.exists(os.path.join(tmpdir, task_id, "attachments", f"{task_id}ocen.zip"))


@pytest.mark.parametrize("create_package", [util.get_dlazaw_package()], indirect=True)
def test_no_ocen_and_dlazaw(create_package):
"""
Test if ocen archive is not created when there are no ocen tests.
Also test if dlazaw archive is created.
"""
parser = configure_parsers()
args = parser.parse_args(["export", "--no-statement"])
command = Command()
command.run(args)
task_id = package_util.get_task_id()

with tempfile.TemporaryDirectory() as tmpdir:
with tarfile.open(f'{task_id}.tgz', "r") as tar:
sinol_util.extract_tar(tar, tmpdir)

assert not os.path.exists(os.path.join(tmpdir, task_id, "attachments", f"{task_id}ocen.zip"))
dlazaw_archive = os.path.join(tmpdir, task_id, "attachments", f"dlazaw.zip")
assert os.path.exists(dlazaw_archive)

with zipfile.ZipFile(dlazaw_archive, "r") as zip:
zip.extractall(os.path.join(tmpdir))

assert os.path.exists(os.path.join(tmpdir, "dlazaw"))
assert os.path.exists(os.path.join(tmpdir, "dlazaw", "epic_file"))
5 changes: 5 additions & 0 deletions tests/packages/dlazaw/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
title: Package with no ocen files and dlazaw dir
sinol_task_id: dla
sinol_contest_type: oi
time_limit: 1000
memory_limit: 10240
1 change: 1 addition & 0 deletions tests/packages/dlazaw/dlazaw/epic_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a file
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions tests/packages/dlazaw/prog/dla.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
int a, b;
cin >> a >> b;
cout << a + b;
}
9 changes: 9 additions & 0 deletions tests/packages/dlazaw/prog/dlaingen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <bits/stdc++.h>

using namespace std;

int main() {
ofstream f("ocen1a.in");
f << "1 1\n";
f.close();
}
7 changes: 7 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ def get_bad_tests_package_path():
return os.path.join(os.path.dirname(__file__), "packages", "bad_tests")


def get_dlazaw_package():
"""
Get path to package with dlazaw dir and no ocen tests (/tests/packages/dlazaw)
"""
return os.path.join(os.path.dirname(__file__), "packages", "dlazaw")


def create_ins(package_path, task_id):
"""
Create .in files for package.
Expand Down

0 comments on commit 3b4bd7f

Please sign in to comment.