Skip to content

Commit

Permalink
[frontend/tests] Removing and migrating legacy tests (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
Drumor committed Oct 25, 2022
1 parent 3599289 commit 39f3a86
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 1,178 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install -y libtidy5deb1 libzmq3-dev
pip3 install nose==1.3.7 selenium==3.141.0 coverage pyvirtualdisplay pytest
pip3 install coverage pytest
- name: Start services
run: |
Expand All @@ -41,9 +41,6 @@ jobs:
- name: Mitigate MarkupSafe 2.1+ issues
run: pip3 install --upgrade markupsafe==2.0.1

- name: Launch nose tests
run: nosetests -v --with-coverage --cover-package=inginious --cover-branches --cover-html -I "^test_"

- name: Launch pytest tests
run: coverage run --branch -m pytest -v

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
# pylint: disable=redefined-outer-name
# -*- coding: utf-8 -*-
#
# This file is part of INGInious. See the LICENSE and the COPYRIGHTS files for
# more information about the licensing of this file.

import pytest

import os
import tempfile
import shutil
import copy

from inginious.common.base import directory_compare_from_hash, directory_content_with_hash, hash_file, id_checker, load_json_or_yaml, \
from inginious.common.base import directory_compare_from_hash, directory_content_with_hash, hash_file, id_checker, \
load_json_or_yaml, \
write_json_or_yaml


@pytest.fixture()
def init_tmp_dir(request):
""" Create a temporary folder """
dir_path = tempfile.mkdtemp()
yield (dir_path)
""" Some FUT could create content in the prefix """
shutil.rmtree(dir_path)

class TestIdChecker(object):
""" Test the id checker """

Expand All @@ -31,46 +43,42 @@ def test_id_checker_invalid_3(self):
class TestJSONYAMLReaderWriter(object):
""" Test the functions load_json_or_yaml and write_json_or_yaml """

def setUp(self):
self.dir_path = tempfile.mkdtemp()

def tearDown(self):
shutil.rmtree(self.dir_path)

def test_json_read(self):
with open(os.path.join(self.dir_path, "input.json"), "w") as f:
def test_json_read(self, init_tmp_dir):
tmp_dir = init_tmp_dir
with open(os.path.join(tmp_dir, "input.json"), "w") as f:
f.write('{"key1":"data1","key2":{"key3":[1,2]}}')
assert load_json_or_yaml(os.path.join(self.dir_path, "input.json")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}

def test_json_write(self):
write_json_or_yaml(os.path.join(self.dir_path, "output.json"), {'key1': 'data1', 'key2': {'key3': [1, 2]}})
assert load_json_or_yaml(os.path.join(self.dir_path, "output.json")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}

def test_yaml_read(self):
with open(os.path.join(self.dir_path, "input.yaml"), "w") as f:
assert load_json_or_yaml(os.path.join(tmp_dir, "input.json")) == {'key1': 'data1',
'key2': {'key3': [1, 2]}}

def test_json_write(self, init_tmp_dir):
tmp_dir = init_tmp_dir
write_json_or_yaml(os.path.join(tmp_dir, "output.json"), {'key1': 'data1', 'key2': {'key3': [1, 2]}})
assert load_json_or_yaml(os.path.join(tmp_dir, "output.json")) == {'key1': 'data1',
'key2': {'key3': [1, 2]}}

def test_yaml_read(self, init_tmp_dir):
tmp_dir = init_tmp_dir
with open(os.path.join(tmp_dir, "input.yaml"), "w") as f:
f.write("""
key1: data1
key2:
key3:
- 1
- 2
""")
assert load_json_or_yaml(os.path.join(self.dir_path, "input.yaml")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}
assert load_json_or_yaml(os.path.join(tmp_dir, "input.yaml")) == {'key1': 'data1',
'key2': {'key3': [1, 2]}}

def test_yaml_write(self):
write_json_or_yaml(os.path.join(self.dir_path, "output.yaml"), {'key1': 'data1', 'key2': {'key3': [1, 2]}})
assert load_json_or_yaml(os.path.join(self.dir_path, "output.yaml")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}
def test_yaml_write(self,init_tmp_dir):
tmp_dir = init_tmp_dir
write_json_or_yaml(os.path.join(tmp_dir, "output.yaml"), {'key1': 'data1', 'key2': {'key3': [1, 2]}})
assert load_json_or_yaml(os.path.join(tmp_dir, "output.yaml")) == {'key1': 'data1',
'key2': {'key3': [1, 2]}}


class TestDirectoryHash(object):
""" Test all the functions that involves file hash """

def setUp(self):
self.dir_path = tempfile.mkdtemp()

def tearDown(self):
shutil.rmtree(self.dir_path)

def test_hash_file(self):
with tempfile.TemporaryFile() as tmp:
tmp.write(b"some random text")
Expand All @@ -79,8 +87,9 @@ def test_hash_file(self):
the_hash = hash_file(tmp)
assert the_hash == "07671a038c0eb43723d421693b073c3b"

def test_directory_content_with_hash(self):
test_dir = os.path.join(self.dir_path, "test1")
def test_directory_content_with_hash(self, init_tmp_dir):
temp_dir = init_tmp_dir
test_dir = os.path.join(temp_dir, "test1")

# Create data
os.mkdir(test_dir)
Expand All @@ -98,13 +107,15 @@ def test_directory_content_with_hash(self):

with open(os.path.join(test_dir, "subdir", "file3"), "w") as f:
f.write("random text 3")
goal["subdir/file3"] = ("312aa75e0816015cdb5ef1989de7bf3f", os.stat(os.path.join(test_dir, "subdir", "file3")).st_mode)
goal["subdir/file3"] = (
"312aa75e0816015cdb5ef1989de7bf3f", os.stat(os.path.join(test_dir, "subdir", "file3")).st_mode)

# Test the function
assert directory_content_with_hash(test_dir) == goal

def test_directory_compare_from_hash(self):
test_dir = os.path.join(self.dir_path, "test2")
def test_directory_compare_from_hash(self, init_tmp_dir):
temp_dir = init_tmp_dir
test_dir = os.path.join(temp_dir, "test2")

# Create data
os.mkdir(test_dir)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# pylint: disable=redefined-outer-name
# -*- coding: utf-8 -*-
#
# This file is part of INGInious. See the LICENSE and the COPYRIGHTS files for
# more information about the licensing of this file.

import pytest

import tempfile
import shutil
import os
Expand All @@ -11,15 +14,19 @@
import inginious.common.custom_yaml as yaml


class TestCustomLoad(object):
def setUp(self):
self.dir_path = tempfile.mkdtemp()
@pytest.fixture()
def init_tmp_dir(request):
""" Create a temporary folder """
dir_path = tempfile.mkdtemp()
yield (dir_path)
""" Some FUT could create content in the prefix """
shutil.rmtree(dir_path)

def tearDown(self):
shutil.rmtree(self.dir_path)

def test_load_ordereddict(self):
with open(os.path.join(self.dir_path, "input.yaml"), "w") as f:
class TestCustomLoad(object):
def test_load_ordereddict(self, init_tmp_dir):
tmp_dir = init_tmp_dir
with open(os.path.join(tmp_dir, "input.yaml"), "w") as f:
f.write("""
the: a
order: z
Expand All @@ -29,7 +36,7 @@ def test_load_ordereddict(self):
is: x
important: d
""")
with open(os.path.join(self.dir_path, "input.yaml"), "r") as f:
with open(os.path.join(tmp_dir, "input.yaml"), "r") as f:
loaded = yaml.load(f)
assert type(loaded) == OrderedDict
assert list(loaded.keys()) == ["the", "order", "of", "the_", "keys", "is", "important"]
Expand All @@ -49,18 +56,14 @@ def test_load_string(self):


class TestCustomWrite(object):
def setUp(self):
self.dir_path = tempfile.mkdtemp()

def tearDown(self):
shutil.rmtree(self.dir_path)

def test_write_ordereddict(self):
def test_write_ordereddict(self, init_tmp_dir):
tmp_dir = init_tmp_dir
d = OrderedDict([("the", "a"), ("order", "z"), ("is", "b"), ("important", "y")])
with open(os.path.join(self.dir_path, "output.yaml"), "w") as f:
with open(os.path.join(tmp_dir, "output.yaml"), "w") as f:
yaml.dump(d, f)

with open(os.path.join(self.dir_path, "output.yaml"), "r") as f:
with open(os.path.join(tmp_dir, "output.yaml"), "r") as f:
loaded = yaml.load(f)
assert type(loaded) == OrderedDict
assert list(loaded.keys()) == ["the", "order", "is", "important"]
Expand Down

0 comments on commit 39f3a86

Please sign in to comment.