summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2023-02-17 01:06:26 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2023-02-17 01:06:26 -0600
commita5d9664a9264f45b088cc363331b391a40779b40 (patch)
treeb3d94b185706a60dc3159b405ee04068d1b93a2c /tests
parentb0d48558606fabfb582358077c3c909c2bbb63e1 (diff)
finish testing and polishing, add readmev1.0.0
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py14
-rw-r--r--tests/test_pymdvar.py61
2 files changed, 66 insertions, 9 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..df33848
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,14 @@
+import pytest
+
+
+@pytest.fixture
+def single_var_dict():
+ return {'test': 'value'}
+
+
+@pytest.fixture
+def multi_var_dict():
+ return {'ext': 'jpg',
+ 'test': 'value',
+ 'TEST': 'VALUE',
+ 'SOMETHING_ELSE': 'something_else'}
diff --git a/tests/test_pymdvar.py b/tests/test_pymdvar.py
index 91a97d0..a4c4439 100644
--- a/tests/test_pymdvar.py
+++ b/tests/test_pymdvar.py
@@ -1,3 +1,4 @@
+import os
import pytest
from markdown import markdown
from pymdvar import VariableExtension
@@ -5,31 +6,73 @@ from pymdvar import VariableExtension
def test_empty_input():
in_str: str = ''
+ exp_str: str = markdown(in_str)
out_str: str = markdown(in_str, extensions=[VariableExtension()])
- assert in_str == out_str
+ assert out_str == exp_str
@pytest.mark.parametrize('in_str, exp_str', [
('foo bar', '<p>foo bar</p>'),
('foo *test* bar', '<p>foo <em>test</em> bar</p>'),
- ('foo **test** bar', '<p>foo <strong>test</strong> bar</p>'),
+ ('foo *PYMDVAR_TEST_1* bar', '<p>foo <em>PYMDVAR_TEST_1</em> bar</p>'),
('foo $test bar', '<p>foo $test bar</p>'),
- ('foo *${test* bar', '<p>foo <em>${test</em> bar</p>'),
('foo **$test}** bar', '<p>foo <strong>$test}</strong> bar</p>'),
+ ('foo **$PYMDVAR_TEST_2}** bar', '<p>foo <strong>$PYMDVAR_TEST_2}</strong> bar</p>'),
+ ('foo [link](${test/a.html) bar', '<p>foo <a href="${test/a.html">link</a> bar</p>'),
+ ('foo ![image]($test}/a.jpg) bar', '<p>foo <img alt="image" src="$test}/a.jpg" /> bar</p>')
+])
+def test_no_replacements_config(in_str: str, exp_str: str, single_var_dict: dict[str, str]):
+ out_str: str = markdown(in_str, extensions=[VariableExtension(variables=single_var_dict, enable_env=True)])
+ assert out_str == exp_str
+
+
+@pytest.mark.parametrize('in_str, exp_str', [
+ ('foo *${test}* bar', '<p>foo <em></em> bar</p>'),
+ ('foo *${PYMDVAR_TEST_1}* bar', '<p>foo <em></em> bar</p>'),
+ ('foo [link](${test}/a.html) bar', '<p>foo <a href="/a.html">link</a> bar</p>'),
])
-def test_non_replacements(in_str, exp_str):
+def test_replacements_no_config(in_str: str, exp_str: str):
out_str: str = markdown(in_str, extensions=[VariableExtension()])
assert out_str == exp_str
@pytest.mark.parametrize('in_str, exp_str', [
- ('foo ${test} bar', '<p>foo value bar</p>'),
('foo *${test}* bar', '<p>foo <em>value</em> bar</p>'),
- ('foo **${test}** bar', '<p>foo <strong>value</strong> bar</p>'),
+ ('foo *${PYMDVAR_TEST_1}* bar', '<p>foo <em>1</em> bar</p>'),
+ ('foo ${value} bar', '<p>foo bar</p>'),
+ ('foo **${PYMDVAR_TEST_2}** bar', '<p>foo <strong></strong> bar</p>'),
('foo [link](${test}/a.html) bar', '<p>foo <a href="value/a.html">link</a> bar</p>'),
- ('foo ![image](${test}/a.jpg) bar', '<p>foo <img alt="image" src="value/a.jpg" /> bar</p>'),
+ ('foo ![image](${PYMDVAR_TEST_1}/a.jpg) bar', '<p>foo <img alt="image" src="1/a.jpg" /> bar</p>'),
+ ('foo [link](${PYMDVAR_TEST_2}/a.html) bar', '<p>foo <a href="/a.html">link</a> bar</p>')
])
-def test_simple_replacements(in_str, exp_str):
- out_str: str = markdown(in_str, extensions=[VariableExtension(variables={'test':'value'})])
+def test_simple_replacements(in_str: str, exp_str: str, single_var_dict: dict[str, str]):
+ out_str: str = markdown(in_str, extensions=[VariableExtension(variables=single_var_dict, enable_env=True)])
assert out_str == exp_str
+
+@pytest.mark.parametrize('in_str, exp_str', [
+ ('foo *${test}* bar', '<p>foo <em>value</em> bar</p>'),
+ ('foo *${TEST}* bar', '<p>foo <em>VALUE</em> bar</p>'),
+ ('foo **${SOMETHING_ELSE}** bar', '<p>foo <strong>something_else</strong> bar</p>')
+])
+def test_multivar_replacements(in_str: str, exp_str: str, multi_var_dict: dict[str, str]):
+ out_str: str = markdown(in_str, extensions=[VariableExtension(variables=multi_var_dict)])
+ assert out_str == exp_str
+
+
+@pytest.mark.parametrize('in_str, exp_str', [
+ ('foo *${test}* and **${TEST}** bar', '<p>foo <em>value</em> and <strong>VALUE</strong> bar</p>'),
+ ('foo ![image](${PYMDVAR_TEST_1}/a.${ext}) bar', '<p>foo <img alt="image" src="/a.jpg" /> bar</p>')
+])
+def test_text_multivar_replacements(in_str: str, exp_str: str, multi_var_dict: dict[str, str]):
+ out_str: str = markdown(in_str, extensions=[VariableExtension(variables=multi_var_dict)])
+ assert out_str == exp_str
+
+
+@pytest.mark.parametrize('in_str, exp_str', [
+ ('foo *${test}* and **${TEST}** bar', '<p>foo <em>value</em> and <strong>VALUE</strong> bar</p>'),
+ ('foo ![image](${PYMDVAR_TEST_1}/a.${ext}) bar', '<p>foo <img alt="image" src="/a.jpg" /> bar</p>')
+])
+def test_extension_text_mode(in_str: str, exp_str: str, multi_var_dict: dict[str, str]):
+ out_str: str = markdown(in_str, extensions=['pymdvar'], extension_configs={'pymdvar': {'variables': multi_var_dict}})
+ assert out_str == exp_str