summaryrefslogtreecommitdiff
path: root/creole/tests
diff options
context:
space:
mode:
Diffstat (limited to 'creole/tests')
-rw-r--r--creole/tests/constants.py5
-rw-r--r--creole/tests/test_project_setup.py37
-rw-r--r--creole/tests/test_setup_utils.py74
-rw-r--r--creole/tests/utils/utils.py54
4 files changed, 132 insertions, 38 deletions
diff --git a/creole/tests/constants.py b/creole/tests/constants.py
new file mode 100644
index 0000000..0e276d4
--- /dev/null
+++ b/creole/tests/constants.py
@@ -0,0 +1,5 @@
+from pathlib import Path
+
+import creole
+
+CREOLE_PACKAGE_ROOT = Path(creole.__file__).parent.parent
diff --git a/creole/tests/test_project_setup.py b/creole/tests/test_project_setup.py
new file mode 100644
index 0000000..b589acf
--- /dev/null
+++ b/creole/tests/test_project_setup.py
@@ -0,0 +1,37 @@
+"""
+ :copyleft: 2020 by python-creole team, see AUTHORS for more details.
+ :license: GNU GPL v3 or above, see LICENSE for more details.
+"""
+
+from pathlib import Path
+
+from creole import __version__
+from creole.tests.constants import CREOLE_PACKAGE_ROOT
+
+
+def assert_file_contains_string(file_path, string):
+ with file_path.open('r') as f:
+ for line in f:
+ if string in line:
+ return
+ raise AssertionError(f'File {file_path} does not contain {string!r} !')
+
+
+def test_version():
+ if 'dev' not in __version__:
+ version_string = f'v{__version__}'
+
+ assert_file_contains_string(
+ file_path=Path(CREOLE_PACKAGE_ROOT, 'README.creole'),
+ string=version_string
+ )
+
+ assert_file_contains_string(
+ file_path=Path(CREOLE_PACKAGE_ROOT, 'README.rst'),
+ string=version_string
+ )
+
+ assert_file_contains_string(
+ file_path=Path(CREOLE_PACKAGE_ROOT, 'pyproject.toml'),
+ string=f'version = "{__version__}"'
+ )
diff --git a/creole/tests/test_setup_utils.py b/creole/tests/test_setup_utils.py
index 33d998c..5a7b366 100644
--- a/creole/tests/test_setup_utils.py
+++ b/creole/tests/test_setup_utils.py
@@ -1,45 +1,29 @@
-
"""
unittest for setup_utils
~~~~~~~~~~~~~~~~~~~~~~~~
- https://code.google.com/p/python-creole/wiki/UseInSetup
+ https://github.com/jedie/python-creole/wiki/Use-In-Setup
:copyleft: 2011-2020 by python-creole team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
-
-
+import difflib
+import filecmp
import os
+import shutil
import tempfile
-import warnings
+from pathlib import Path
-import creole
-from creole.setup_utils import get_long_description
+from creole.setup_utils import get_long_description, update_creole_rst_readme
+from creole.tests.constants import CREOLE_PACKAGE_ROOT
from creole.tests.utils.base_unittest import BaseCreoleTest
+from creole.tests.utils.utils import IsolatedFilesystem
-try:
- import docutils # noqa flake8
- DOCUTILS = True
-except ImportError:
- DOCUTILS = False
-
-
-CREOLE_PACKAGE_ROOT = os.path.abspath(os.path.join(os.path.dirname(creole.__file__), ".."))
-TEST_README_DIR = os.path.abspath(os.path.dirname(__file__))
+TEST_README_DIR = Path(__file__).parent
TEST_README_FILENAME = "test_README.creole"
-# TODO: Use @unittest.skipIf if python 2.6 will be not support anymore.
-# @unittest.skipIf(DOCUTILS == False, "docutils not installed.")
class SetupUtilsTests(BaseCreoleTest):
- def run(self, *args, **kwargs):
- # TODO: Remove if python 2.6 will be not support anymore.
- if not DOCUTILS:
- warnings.warn("Skip SetupUtilsTests, because 'docutils' not installed.")
- return
- return super(SetupUtilsTests, self).run(*args, **kwargs)
-
def test_creole_package_path(self):
self.assertTrue(
os.path.isdir(CREOLE_PACKAGE_ROOT),
@@ -123,3 +107,43 @@ class SetupUtilsTests(BaseCreoleTest):
txt = "German Umlaute: ä ö ü ß Ä Ö Ü"
self.assertIn(txt, long_description)
+
+
+def test_update_rst_readme():
+ with IsolatedFilesystem(prefix="temp_dir_prefix"):
+ old_rest_readme_path = Path(Path().cwd(), 'README.rst')
+ shutil.copy(
+ Path(CREOLE_PACKAGE_ROOT, 'README.rst'),
+ old_rest_readme_path
+ )
+ try:
+ rest_readme_path = update_creole_rst_readme()
+ assert str(rest_readme_path.relative_to(CREOLE_PACKAGE_ROOT)) == 'README.rst'
+
+ if filecmp.cmp(rest_readme_path, old_rest_readme_path, shallow=False) is True:
+ return
+
+ # On CI the file modification time maybe not the same.
+ # So skip the last line and compare again.
+
+ with old_rest_readme_path.open('r') as f:
+ from_file = [line.rstrip() for line in f][:-1]
+
+ with rest_readme_path.open('r') as f:
+ to_file = [line.rstrip() for line in f][:-1]
+
+ if from_file == to_file:
+ return
+
+ diff = '\n'.join(
+ line
+ for line in difflib.Differ().compare(from_file, to_file)
+ if line[0] != ' '
+ )
+ raise AssertionError(f'README.rst is not up-to-date:\n{diff}')
+ finally:
+ # restore the origin file
+ shutil.copy(
+ old_rest_readme_path,
+ Path(CREOLE_PACKAGE_ROOT, 'README.rst'),
+ )
diff --git a/creole/tests/utils/utils.py b/creole/tests/utils/utils.py
index 005f6c4..dd60454 100644
--- a/creole/tests/utils/utils.py
+++ b/creole/tests/utils/utils.py
@@ -1,26 +1,21 @@
-# coding: utf-8
-
-
"""
unitest generic utils
~~~~~~~~~~~~~~~~~~~~~
Generic utils useable for a markup test.
- :copyleft: 2008-2011 by python-creole team, see AUTHORS for more details.
+ :copyleft: 2008-2020 by python-creole team, see AUTHORS for more details.
:license: GNU GPL v3 or above, see LICENSE for more details.
"""
import difflib
+import os
+import shutil
+import tempfile
import textwrap
import unittest
-
-# error output format:
-# =1 -> via repr()
-# =2 -> raw
-VERBOSE = 1
-#VERBOSE = 2
+from pathlib import Path
def make_diff(block1, block2):
@@ -31,7 +26,7 @@ def make_diff(block1, block2):
diff = d.compare(block1, block2)
- result = ["%2s %s\n" % (line, i) for line, i in enumerate(diff)]
+ result = [f"{line:>2} {i}\n" for line, i in enumerate(diff)]
return "".join(result)
@@ -40,11 +35,17 @@ class MarkupTest(unittest.TestCase):
Special error class: Try to display markup errors in a better way.
"""
+ # error output format:
+ # =1 -> via repr()
+ # =2 -> raw
+ VERBOSE = 1
+ #VERBOSE = 2
+
def _format_output(self, txt):
txt = txt.split("\\n")
- if VERBOSE == 1:
+ if self.VERBOSE == 1:
txt = "".join(['%s\\n\n' % i for i in txt])
- elif VERBOSE == 2:
+ elif self.VERBOSE == 2:
txt = "".join(['%s\n' % i for i in txt])
return txt
@@ -83,3 +84,30 @@ class MarkupTest(unittest.TestCase):
txt = txt[1:]
return txt
+
+
+class IsolatedFilesystem:
+ """
+ Context manager, e.g.:
+ with IsolatedFilesystem(prefix="temp_dir_prefix"):
+ print("I'm in the temp path here: %s" % Path().cwd())
+ """
+
+ def __init__(self, prefix=None):
+ super().__init__()
+
+ self.prefix = prefix
+
+ def __enter__(self):
+ print(f"Use prefix: {self.prefix!r}")
+
+ self.cwd = Path().cwd()
+ self.temp_path = tempfile.mkdtemp(prefix=self.prefix)
+ os.chdir(self.temp_path)
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ os.chdir(str(self.cwd)) # str() needed for older python <=3.5
+ try:
+ shutil.rmtree(self.temp_path)
+ except OSError:
+ pass