mirror of https://github.com/CIRCL/PyCIRCLean
Add tests for helpers.py
parent
14b9d71da8
commit
6a96d3f7a2
|
@ -2,6 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import unittest.mock as mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -14,6 +15,14 @@ fixture = pytest.fixture
|
||||||
|
|
||||||
class TestFileBase:
|
class TestFileBase:
|
||||||
|
|
||||||
|
@fixture(scope='class')
|
||||||
|
def dest_dir_path(self, tmpdir_factory):
|
||||||
|
return tmpdir_factory.mktemp('dest').strpath
|
||||||
|
|
||||||
|
@fixture(scope='class')
|
||||||
|
def src_dir_path(self, tmpdir_factory):
|
||||||
|
return tmpdir_factory.mktemp('src').strpath
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def symlink_file(self, tmpdir):
|
def symlink_file(self, tmpdir):
|
||||||
file_path = tmpdir.join('test.txt')
|
file_path = tmpdir.join('test.txt')
|
||||||
|
@ -25,11 +34,10 @@ class TestFileBase:
|
||||||
return FileBase(symlink_path, symlink_path)
|
return FileBase(symlink_path, symlink_path)
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def temp_file(self, tmpdir):
|
def temp_file(self, src_dir_path, dst_dir_path):
|
||||||
file_path = tmpdir.join('test.txt')
|
file_path = os.path.join(src_dir_path, 'test.txt')
|
||||||
file_path.write('testing')
|
file_path.write('testing')
|
||||||
file_path = file_path.strpath
|
return FileBase(file_path, dst_dir_path)
|
||||||
return FileBase(file_path, file_path)
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def temp_file_no_ext(self, tmpdir):
|
def temp_file_no_ext(self, tmpdir):
|
||||||
|
@ -42,9 +50,13 @@ class TestFileBase:
|
||||||
def file_marked_dangerous(self):
|
def file_marked_dangerous(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init_identify_filename(self):
|
@mock.patch('kittengroomer.helpers.magic')
|
||||||
|
def test_init_identify_filename(self, mock_magic):
|
||||||
"""Init should identify the filename correctly for src_path."""
|
"""Init should identify the filename correctly for src_path."""
|
||||||
pass
|
src_path = 'src/test.txt'
|
||||||
|
dst_path = 'dst/test.txt'
|
||||||
|
file = FileBase(src_path, dst_path)
|
||||||
|
assert file.filename == 'test.txt'
|
||||||
|
|
||||||
def test_init_uppercase_filename(self):
|
def test_init_uppercase_filename(self):
|
||||||
"""Init should coerce filenames to lowercase."""
|
"""Init should coerce filenames to lowercase."""
|
||||||
|
@ -138,43 +150,38 @@ class TestFileBase:
|
||||||
def test_force_ext_change(self):
|
def test_force_ext_change(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_force_ext_correct(self, generic_conf_file):
|
def test_force_ext_correct(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_create_metadata_file_new(self, temp_file):
|
def test_create_metadata_file_new(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_create_metadata_file_already_exists(self):
|
def test_create_metadata_file_already_exists(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@skip
|
|
||||||
class TestKittenGroomerBase:
|
class TestKittenGroomerBase:
|
||||||
|
|
||||||
@fixture
|
@fixture(scope='class')
|
||||||
def source_directory(self):
|
def src_dir_path(self, tmpdir_factory):
|
||||||
return 'tests/dangerous'
|
return tmpdir_factory.mktemp('src').strpath
|
||||||
|
|
||||||
|
@fixture(scope='class')
|
||||||
|
def dest_dir_path(self, tmpdir_factory):
|
||||||
|
return tmpdir_factory.mktemp('dest').strpath
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def dest_directory(self):
|
def generic_groomer(self, src_dir_path, dest_dir_path):
|
||||||
return 'tests/dst'
|
return KittenGroomerBase(src_dir_path, dest_dir_path)
|
||||||
|
|
||||||
@fixture
|
def test_list_all_files_includes_file(self, tmpdir):
|
||||||
def generic_groomer(self, source_directory, dest_directory):
|
|
||||||
return KittenGroomerBase(source_directory, dest_directory)
|
|
||||||
|
|
||||||
def test_create(self, generic_groomer):
|
|
||||||
assert generic_groomer
|
|
||||||
|
|
||||||
def test_instantiation(self, source_directory, dest_directory):
|
|
||||||
KittenGroomerBase(source_directory, dest_directory)
|
|
||||||
|
|
||||||
def test_list_all_files(self, tmpdir):
|
|
||||||
file = tmpdir.join('test.txt')
|
file = tmpdir.join('test.txt')
|
||||||
file.write('testing')
|
file.write('testing')
|
||||||
|
files = KittenGroomerBase.list_all_files(KittenGroomerBase, tmpdir.strpath)
|
||||||
|
assert file.strpath in files
|
||||||
|
|
||||||
|
def test_list_all_files_excludes_dir(self, tmpdir):
|
||||||
testdir = tmpdir.join('testdir')
|
testdir = tmpdir.join('testdir')
|
||||||
os.mkdir(testdir.strpath)
|
os.mkdir(testdir.strpath)
|
||||||
simple_groomer = KittenGroomerBase(tmpdir.strpath, tmpdir.strpath)
|
files = KittenGroomerBase.list_all_files(KittenGroomerBase, tmpdir.strpath)
|
||||||
files = simple_groomer.list_all_files(simple_groomer.src_root_path)
|
|
||||||
assert file.strpath in files
|
|
||||||
assert testdir.strpath not in files
|
assert testdir.strpath not in files
|
||||||
|
|
Loading…
Reference in New Issue