mirror of
https://github.com/novoid/date2name.git
synced 2026-06-14 11:01:19 +00:00
Initialize folder testing (elementary tests).
First tests on generation/remove of folders before date2name's action on folders.
This commit is contained in:
parent
d1f5672db0
commit
ba14f65f34
2 changed files with 55 additions and 19 deletions
|
|
@ -32,15 +32,23 @@ import pytest
|
||||||
|
|
||||||
PROGRAM = str("./date2name/__init__.py")
|
PROGRAM = str("./date2name/__init__.py")
|
||||||
TFILE = str("test_file.txt") # the intermediate test file written
|
TFILE = str("test_file.txt") # the intermediate test file written
|
||||||
|
TFOLDER = str("test_folder") # for complementary check on folders
|
||||||
|
|
||||||
def prepare_testfile():
|
def prepare_testfile(name=TFILE):
|
||||||
"""The creation of the test file."""
|
"""The creation of the test file."""
|
||||||
with open (TFILE, mode="w") as newfile:
|
with open (name, mode="w") as newfile:
|
||||||
newfile.write("This is the test file for test_date2name.py.")
|
newfile.write("This is the test file for test_date2name.py.")
|
||||||
# adjust modification time stamp, based on
|
# adjust modification time stamp, based on
|
||||||
# https://stackoverflow.com/questions/53111614/how-to-modify-the-file-modification-date-with-python-on-mac
|
# https://stackoverflow.com/questions/53111614/how-to-modify-the-file-modification-date-with-python-on-mac
|
||||||
result = os.stat(TFILE)
|
result = os.stat(name)
|
||||||
os.utime(TFILE, (result.st_atime, result.st_mtime + 10.0))
|
os.utime(name, (result.st_atime, result.st_mtime + 10.0))
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_testfolder(name=TFOLDER):
|
||||||
|
"""Create a testfolder."""
|
||||||
|
os.mkdir(name)
|
||||||
|
result = os.stat(name)
|
||||||
|
os.utime(name, (result.st_atime, result.st_mtime + 10.0))
|
||||||
|
|
||||||
|
|
||||||
def query_creation_time(name=TFILE):
|
def query_creation_time(name=TFILE):
|
||||||
|
|
@ -56,10 +64,20 @@ def query_modification_time(name=TFILE):
|
||||||
modified = str(datetime.fromtimestamp(modified))
|
modified = str(datetime.fromtimestamp(modified))
|
||||||
return modified
|
return modified
|
||||||
|
|
||||||
def test_create_remove_testfile():
|
def test_create_remove_testfile(name=TFILE):
|
||||||
"""Merely check if the test file may be written and removed."""
|
"""Merely check if the test file may be written and removed."""
|
||||||
prepare_testfile()
|
prepare_testfile(name=TFILE)
|
||||||
os.remove(TFILE)
|
assert os.path.isfile(name)
|
||||||
|
os.remove(name)
|
||||||
|
assert os.path.isfile(name) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_remove_testfolder(name=TFOLDER):
|
||||||
|
"""Probe the generation/removal of a test folder."""
|
||||||
|
prepare_testfolder(name=TFOLDER)
|
||||||
|
assert os.path.isdir(name)
|
||||||
|
os.rmdir(name)
|
||||||
|
assert os.path.isdir(name) is False
|
||||||
|
|
||||||
|
|
||||||
def test_script_existence():
|
def test_script_existence():
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,7 @@
|
||||||
|
|
||||||
PROGRAM = str("./date2name/__init__.py")
|
PROGRAM = str("./date2name/__init__.py")
|
||||||
TFILE = str("test_file.txt") # the intermediate test file written
|
TFILE = str("test_file.txt") # the intermediate test file written
|
||||||
|
TFOLDER = str("test_folder") # for complementary check on folders
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -128,16 +129,23 @@
|
||||||
Define actions which are going to be used multiple times.
|
Define actions which are going to be used multiple times.
|
||||||
|
|
||||||
#+begin_src python :tangle test_date2name.py
|
#+begin_src python :tangle test_date2name.py
|
||||||
def prepare_testfile():
|
def prepare_testfile(name=TFILE):
|
||||||
"""The creation of the test file."""
|
"""The creation of the test file."""
|
||||||
with open (TFILE, mode="w") as newfile:
|
with open (name, mode="w") as newfile:
|
||||||
newfile.write("This is the test file for test_date2name.py.")
|
newfile.write("This is the test file for test_date2name.py.")
|
||||||
# adjust modification time stamp, based on
|
# adjust modification time stamp, based on
|
||||||
# https://stackoverflow.com/questions/53111614/how-to-modify-the-file-modification-date-with-python-on-mac
|
# https://stackoverflow.com/questions/53111614/how-to-modify-the-file-modification-date-with-python-on-mac
|
||||||
result = os.stat(TFILE)
|
result = os.stat(name)
|
||||||
os.utime(TFILE, (result.st_atime, result.st_mtime + 10.0))
|
os.utime(name, (result.st_atime, result.st_mtime + 10.0))
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_testfolder(name=TFOLDER):
|
||||||
|
"""Create a testfolder."""
|
||||||
|
os.mkdir(name)
|
||||||
|
result = os.stat(name)
|
||||||
|
os.utime(name, (result.st_atime, result.st_mtime + 10.0))
|
||||||
|
|
||||||
|
|
||||||
def query_creation_time(name=TFILE):
|
def query_creation_time(name=TFILE):
|
||||||
"""Determine the time of creation of the file/folder."""
|
"""Determine the time of creation of the file/folder."""
|
||||||
created = os.stat(name).st_ctime
|
created = os.stat(name).st_ctime
|
||||||
|
|
@ -158,20 +166,30 @@
|
||||||
These tests do not modify a file, nor folder by =date2time=.
|
These tests do not modify a file, nor folder by =date2time=.
|
||||||
|
|
||||||
#+begin_src python :tangle test_date2name.py
|
#+begin_src python :tangle test_date2name.py
|
||||||
def test_create_remove_testfile():
|
def test_create_remove_testfile(name=TFILE):
|
||||||
"""Merely check if the test file may be written and removed."""
|
"""Merely check if the test file may be written and removed."""
|
||||||
prepare_testfile()
|
prepare_testfile(name=TFILE)
|
||||||
os.remove(TFILE)
|
assert os.path.isfile(name)
|
||||||
|
os.remove(name)
|
||||||
|
assert os.path.isfile(name) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_remove_testfolder(name=TFOLDER):
|
||||||
|
"""Probe the generation/removal of a test folder."""
|
||||||
|
prepare_testfolder(name=TFOLDER)
|
||||||
|
assert os.path.isdir(name)
|
||||||
|
os.rmdir(name)
|
||||||
|
assert os.path.isdir(name) is False
|
||||||
|
|
||||||
|
|
||||||
def test_script_existence():
|
def test_script_existence():
|
||||||
"""Merely check for the script's presence."""
|
"""Merely check for the script's presence."""
|
||||||
assert os.path.isfile(PROGRAM)
|
assert os.path.isfile(PROGRAM)
|
||||||
|
|
||||||
|
|
||||||
def test_script_version():
|
def test_script_version():
|
||||||
"""Check for the correct output of the version.
|
"""Check for the correct output of the version.
|
||||||
|
|
||||||
CLI equivalence: date2name --version """
|
CLI equivalence: date2name --version """
|
||||||
out = getoutput(f"python3 {PROGRAM} --version")
|
out = getoutput(f"python3 {PROGRAM} --version")
|
||||||
assert out.strip() == "__init__.py 2018-05-09"
|
assert out.strip() == "__init__.py 2018-05-09"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue