Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 7, 2024
1 parent 0670c9e commit 5dfdfe4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tests/commands/export/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sinol_make import configure_parsers
from sinol_make import util as sinol_util
from sinol_make.commands.doc import Command as DocCommand
from sinol_make.helpers import paths
from sinol_make.helpers import paths, cache
from tests import util
from tests.fixtures import create_package
from .util import *
Expand Down Expand Up @@ -54,6 +54,7 @@ def _set_contest_type(contest_type):
os.remove(f'{task_id}.tgz')
if os.path.exists(paths.get_cache_path()):
shutil.rmtree(paths.get_cache_path())
cache.create_cache_dirs()


@pytest.mark.parametrize("create_package", [util.get_simple_package_path(), util.get_library_package_path(),
Expand Down
1 change: 1 addition & 0 deletions tests/commands/gen/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def test_missing_output_files(create_package):
assert os.path.exists(outs[0])
shutil.rmtree(paths.get_cache_path())
os.unlink(os.path.join(package_path, "in", ".md5sums"))
cache.create_cache_dirs()


@pytest.mark.parametrize("create_package", [util.get_shell_ingen_pack_path(), util.get_simple_package_path()],
Expand Down
5 changes: 4 additions & 1 deletion tests/commands/verify/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import shutil
from linecache import cache

import pytest

from sinol_make import configure_parsers
from sinol_make import util as sm_util
from sinol_make.commands.verify import Command
from sinol_make.helpers import package_util, paths, func_cache
from sinol_make.helpers import package_util, paths, func_cache, cache
from tests import util
from tests.fixtures import create_package

Expand Down Expand Up @@ -112,6 +114,7 @@ def test_scores_not_100(capsys, create_package):
for contest_type in ["oi", "oij"]:
if os.path.exists(paths.get_cache_path()):
shutil.rmtree(paths.get_cache_path())
cache.create_cache_dirs()
config = package_util.get_config()
config["sinol_contest_type"] = contest_type
sm_util.save_config(config)
Expand Down
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import multiprocessing as mp

from sinol_make import util
from sinol_make.helpers import compile, paths
from sinol_make.helpers import compile, paths, cache
from sinol_make.interfaces.Errors import CompilationError


Expand Down Expand Up @@ -69,6 +69,11 @@ def pytest_configure(config):

# We remove tests cache as it may interfere with testing.
for package in packages:
cwd = os.getcwd()
os.chdir(package)
cache.create_cache_dirs()
os.chdir(cwd)

for md5sum_file in glob.glob(os.path.join(package, ".cache", "md5sums", "*")):
try:
with open(md5sum_file, "r") as f:
Expand Down
2 changes: 2 additions & 0 deletions tests/helpers/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
def test_compilation_caching():
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
cache.create_cache_dirs()
program = os.path.join(tmpdir, 'program.cpp')
open(program, 'w').write('int main() { return 0; }')

Expand Down Expand Up @@ -45,6 +46,7 @@ def test_compilation_caching():
def test_cache():
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
cache.create_cache_dirs()
assert cache.get_cache_file("abc.cpp") == CacheFile()

cache_file = CacheFile(
Expand Down
3 changes: 2 additions & 1 deletion tests/helpers/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
import tempfile

from sinol_make.helpers.cache import save_compiled, check_compiled
from sinol_make.helpers.cache import save_compiled, check_compiled, create_cache_dirs
from tests import util
from tests.fixtures import create_package
from tests.commands.gen.test_integration import simple_run
Expand All @@ -11,6 +11,7 @@
def test_compilation_caching():
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
create_cache_dirs()
with open(os.path.join(os.getcwd(), "test.txt"), "w") as f:
f.write("Test data")
with open(os.path.join(os.getcwd(), "test.e"), "w") as f:
Expand Down

0 comments on commit 5dfdfe4

Please sign in to comment.