From 7188eacd073c07a433b70d2585a2cfff43be3220 Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 13:56:06 +0200 Subject: [PATCH 01/15] Automagically set up framework --- .github/workflows/python-package.yml | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..e56abb6 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,40 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From d46841fe05d36c8cedb3fb978b78ee97f6815593 Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:47:30 +0200 Subject: [PATCH 02/15] first-shot test for jqlcomposer first try with first file - there needs to be much more --- .github/workflows/python-package.yml | 2 +- test/expect1.txt | 1 + test/test1.json | 5 +++++ test/test_jqlcomposer.py | 23 +++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/expect1.txt create mode 100644 test/test1.json create mode 100644 test/test_jqlcomposer.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index e56abb6..e03138c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -37,4 +37,4 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest + pytest test diff --git a/test/expect1.txt b/test/expect1.txt new file mode 100644 index 0000000..8d4ab79 --- /dev/null +++ b/test/expect1.txt @@ -0,0 +1 @@ +("month IN (June, July, August)") AND (temperature > 20) \ No newline at end of file diff --git a/test/test1.json b/test/test1.json new file mode 100644 index 0000000..b1f0e02 --- /dev/null +++ b/test/test1.json @@ -0,0 +1,5 @@ +{ + "summer": "{month_in_long_day_territory} AND {temperature_above_lukewarm}", + "month_in_long_day_territory": "month IN (June, July, August)", + "temperature_above_lukewarm": "temperature > 20" +} \ No newline at end of file diff --git a/test/test_jqlcomposer.py b/test/test_jqlcomposer.py new file mode 100644 index 0000000..3c25c7e --- /dev/null +++ b/test/test_jqlcomposer.py @@ -0,0 +1,23 @@ +import jqlcomposer.jqlcomposer +import subprocess +import filecmp + +TEST_TERMS=["summer"] + +test_jqlcomposer_main_asfile(): + for i in xrange(len(TEST_TERMS)): + idx = i+1 + with open(f"testout{idx}.txt", "w") as outfile + subprocess.run(["python", "jqlcomposer.py", TEST_TERMS[i], "--filename", f"test{idx}.json"], stdout=outfile) + assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") + +test_jqlcomposer_main_astext(): + for i in xrange(len(TEST_TERMS)): + idx = i+1 + json_contents = "" + with open(f"test{idx}.json", "r") as infile: + json_contents = infile.read() + with open(f"testout{idx}.txt", "w") as outfile + subprocess.run(["python", "jqlcomposer.py", TEST_TERMS[i], f'"{json_contents}"'], stdout=outfile) + assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") + From 77bc4617188e73a6df447734145fc77ce32ade8c Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:48:30 +0200 Subject: [PATCH 03/15] def the test functions --- test/test_jqlcomposer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_jqlcomposer.py b/test/test_jqlcomposer.py index 3c25c7e..fa30974 100644 --- a/test/test_jqlcomposer.py +++ b/test/test_jqlcomposer.py @@ -4,14 +4,14 @@ TEST_TERMS=["summer"] -test_jqlcomposer_main_asfile(): +def test_jqlcomposer_main_asfile(): for i in xrange(len(TEST_TERMS)): idx = i+1 with open(f"testout{idx}.txt", "w") as outfile subprocess.run(["python", "jqlcomposer.py", TEST_TERMS[i], "--filename", f"test{idx}.json"], stdout=outfile) assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") -test_jqlcomposer_main_astext(): +def test_jqlcomposer_main_astext(): for i in xrange(len(TEST_TERMS)): idx = i+1 json_contents = "" From 304ce9ed70c1d2c4bde1810a69a9e3e6566c1205 Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:49:26 +0200 Subject: [PATCH 04/15] *sigh* --- test/test_jqlcomposer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_jqlcomposer.py b/test/test_jqlcomposer.py index fa30974..5558366 100644 --- a/test/test_jqlcomposer.py +++ b/test/test_jqlcomposer.py @@ -7,7 +7,7 @@ def test_jqlcomposer_main_asfile(): for i in xrange(len(TEST_TERMS)): idx = i+1 - with open(f"testout{idx}.txt", "w") as outfile + with open(f"testout{idx}.txt", "w") as outfile: subprocess.run(["python", "jqlcomposer.py", TEST_TERMS[i], "--filename", f"test{idx}.json"], stdout=outfile) assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") @@ -17,7 +17,7 @@ def test_jqlcomposer_main_astext(): json_contents = "" with open(f"test{idx}.json", "r") as infile: json_contents = infile.read() - with open(f"testout{idx}.txt", "w") as outfile + with open(f"testout{idx}.txt", "w") as outfile: subprocess.run(["python", "jqlcomposer.py", TEST_TERMS[i], f'"{json_contents}"'], stdout=outfile) assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") From 5654999c4ecaa1ddc796f5269a361b441a73389f Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:11:47 +0200 Subject: [PATCH 05/15] next --- test/test_jqlcomposer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_jqlcomposer.py b/test/test_jqlcomposer.py index 5558366..d0ae552 100644 --- a/test/test_jqlcomposer.py +++ b/test/test_jqlcomposer.py @@ -5,14 +5,14 @@ TEST_TERMS=["summer"] def test_jqlcomposer_main_asfile(): - for i in xrange(len(TEST_TERMS)): + for i in range(len(TEST_TERMS)): idx = i+1 with open(f"testout{idx}.txt", "w") as outfile: subprocess.run(["python", "jqlcomposer.py", TEST_TERMS[i], "--filename", f"test{idx}.json"], stdout=outfile) assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") def test_jqlcomposer_main_astext(): - for i in xrange(len(TEST_TERMS)): + for i in range(len(TEST_TERMS)): idx = i+1 json_contents = "" with open(f"test{idx}.json", "r") as infile: From 8d32b8f1c4ce9672eff45d4f33a7ab9dbb375581 Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:21:49 +0200 Subject: [PATCH 06/15] add init files hoping that will set the root path correctly for the test to find it --- __init__.py | 0 jqlcomposer/__init__.py | 0 lsconvert/__init__.py | 0 minecraft/__init__.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 __init__.py create mode 100644 jqlcomposer/__init__.py create mode 100644 lsconvert/__init__.py create mode 100644 minecraft/__init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jqlcomposer/__init__.py b/jqlcomposer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lsconvert/__init__.py b/lsconvert/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/minecraft/__init__.py b/minecraft/__init__.py new file mode 100644 index 0000000..e69de29 From 42ad8b983f3f9762419e4a58c1d068ef4ffd3dca Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:23:31 +0200 Subject: [PATCH 07/15] ? --- test/__init__.py | 0 test/test_jqlcomposer.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 test/__init__.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_jqlcomposer.py b/test/test_jqlcomposer.py index d0ae552..a996da7 100644 --- a/test/test_jqlcomposer.py +++ b/test/test_jqlcomposer.py @@ -1,4 +1,4 @@ -import jqlcomposer.jqlcomposer +from jqlcomposer import jqlcomposer import subprocess import filecmp From c2c21acae57e9c3ba5e250250a027684a592affa Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:25:58 +0200 Subject: [PATCH 08/15] path broken? --- test/test_jqlcomposer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_jqlcomposer.py b/test/test_jqlcomposer.py index a996da7..fb1b8f1 100644 --- a/test/test_jqlcomposer.py +++ b/test/test_jqlcomposer.py @@ -1,4 +1,4 @@ -from jqlcomposer import jqlcomposer +import jqlcomposer import subprocess import filecmp From d1bedc6696b814cdc56765b35696d4527d07c7b4 Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:30:58 +0200 Subject: [PATCH 09/15] importlib? --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index e03138c..53fbffc 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -37,4 +37,4 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest test + pytest --import-mode=importlib test From 574cd9fa7fe50d885aff86a56b2b76b47251c8f8 Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:31:54 +0200 Subject: [PATCH 10/15] no dir? --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 53fbffc..9d93237 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -37,4 +37,4 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest --import-mode=importlib test + pytest --import-mode=importlib From 5873f3bc6ceb10eb691cf92914e6c4919ca0f7d6 Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 20:56:34 +0200 Subject: [PATCH 11/15] try using a src directory --- {jqlcomposer => src/jqlcomposer}/__init__.py | 0 {jqlcomposer => src/jqlcomposer}/jqlcomposer.py | 0 {jqlcomposer => src/jqlcomposer}/sample.json | 0 {lsconvert => src/lsconvert}/__init__.py | 0 {lsconvert => src/lsconvert}/lsconvert.py | 0 {minecraft => src/minecraft}/__init__.py | 0 {minecraft => src/minecraft}/hmdin.py | 0 test/test_jqlcomposer.py | 2 +- 8 files changed, 1 insertion(+), 1 deletion(-) rename {jqlcomposer => src/jqlcomposer}/__init__.py (100%) rename {jqlcomposer => src/jqlcomposer}/jqlcomposer.py (100%) rename {jqlcomposer => src/jqlcomposer}/sample.json (100%) rename {lsconvert => src/lsconvert}/__init__.py (100%) rename {lsconvert => src/lsconvert}/lsconvert.py (100%) rename {minecraft => src/minecraft}/__init__.py (100%) rename {minecraft => src/minecraft}/hmdin.py (100%) diff --git a/jqlcomposer/__init__.py b/src/jqlcomposer/__init__.py similarity index 100% rename from jqlcomposer/__init__.py rename to src/jqlcomposer/__init__.py diff --git a/jqlcomposer/jqlcomposer.py b/src/jqlcomposer/jqlcomposer.py similarity index 100% rename from jqlcomposer/jqlcomposer.py rename to src/jqlcomposer/jqlcomposer.py diff --git a/jqlcomposer/sample.json b/src/jqlcomposer/sample.json similarity index 100% rename from jqlcomposer/sample.json rename to src/jqlcomposer/sample.json diff --git a/lsconvert/__init__.py b/src/lsconvert/__init__.py similarity index 100% rename from lsconvert/__init__.py rename to src/lsconvert/__init__.py diff --git a/lsconvert/lsconvert.py b/src/lsconvert/lsconvert.py similarity index 100% rename from lsconvert/lsconvert.py rename to src/lsconvert/lsconvert.py diff --git a/minecraft/__init__.py b/src/minecraft/__init__.py similarity index 100% rename from minecraft/__init__.py rename to src/minecraft/__init__.py diff --git a/minecraft/hmdin.py b/src/minecraft/hmdin.py similarity index 100% rename from minecraft/hmdin.py rename to src/minecraft/hmdin.py diff --git a/test/test_jqlcomposer.py b/test/test_jqlcomposer.py index fb1b8f1..a996da7 100644 --- a/test/test_jqlcomposer.py +++ b/test/test_jqlcomposer.py @@ -1,4 +1,4 @@ -import jqlcomposer +from jqlcomposer import jqlcomposer import subprocess import filecmp From 9c9b6e1d353120c5c04649b8959b07fa140856fa Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 21:02:19 +0200 Subject: [PATCH 12/15] next try all scripts toplevel in src, don't import because the package isn't even used from code. --- README.md | 21 ++++++++++++++++++--- __init__.py => src/__init__.py | 0 src/{jqlcomposer => }/jqlcomposer.py | 0 src/jqlcomposer/sample.json | 5 ----- src/{lsconvert => }/lsconvert.py | 0 src/lsconvert/__init__.py | 0 test/__init__.py | 0 {src/jqlcomposer => tests}/__init__.py | 0 {test => tests}/expect1.txt | 0 {test => tests}/test1.json | 0 {test => tests}/test_jqlcomposer.py | 5 ++--- 11 files changed, 20 insertions(+), 11 deletions(-) rename __init__.py => src/__init__.py (100%) rename src/{jqlcomposer => }/jqlcomposer.py (100%) delete mode 100644 src/jqlcomposer/sample.json rename src/{lsconvert => }/lsconvert.py (100%) delete mode 100644 src/lsconvert/__init__.py delete mode 100644 test/__init__.py rename {src/jqlcomposer => tests}/__init__.py (100%) rename {test => tests}/expect1.txt (100%) rename {test => tests}/test1.json (100%) rename {test => tests}/test_jqlcomposer.py (69%) diff --git a/README.md b/README.md index 5914044..583abab 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,18 @@ It will enclose the expansion of sub-queries in parentheses while expanding, in In order to use one query inside another, use the sub-query's name in brackets inside the outer query. See sample.json for an example. +Sample input: + + { + "home": "{go_to} next {corner}", + "go_to": "See you", + "corner": "Saturday" + } + +Sample output: + + (See you) next (Saturday) + ## How Many Do I Need? The minecraft/hmdin script is basically a counting formatter that can help you keep track of large item quantities in Minecraft. By default, it will print a human-readable listing of all nonzero "units of quantity" necessary to amass the specified amount of items. @@ -69,6 +81,9 @@ You can specify a nonstandard stack size (e.g. 16 for eggs or similar) using `-- The actual helper/split functions are: - hmdin(count, stack_size=64, container_size=27) # will return the tuple of , , - pretty_print(chests, stacks, items) # will format the list of items as human readable (without prefix), e.g. "3 chests and 14 items" - csv_print(chests, stacks, items, separator=",") #will format the list of all three items for CSV output, e.g. comma-separated \ No newline at end of file + # will return the tuple of , , + hmdin(count, stack_size=64, container_size=27) + # will format the list of items as human readable (without prefix), e.g. "3 chests and 14 items" + pretty_print(chests, stacks, items) + #will format the list of all three items for CSV output, e.g. comma-separated + csv_print(chests, stacks, items, separator=",") \ No newline at end of file diff --git a/__init__.py b/src/__init__.py similarity index 100% rename from __init__.py rename to src/__init__.py diff --git a/src/jqlcomposer/jqlcomposer.py b/src/jqlcomposer.py similarity index 100% rename from src/jqlcomposer/jqlcomposer.py rename to src/jqlcomposer.py diff --git a/src/jqlcomposer/sample.json b/src/jqlcomposer/sample.json deleted file mode 100644 index 3d6094d..0000000 --- a/src/jqlcomposer/sample.json +++ /dev/null @@ -1,5 +0,0 @@ -{ -"home": "{go_to} next {corner}", -"go_to": "See you", -"corner": "Saturday" -} \ No newline at end of file diff --git a/src/lsconvert/lsconvert.py b/src/lsconvert.py similarity index 100% rename from src/lsconvert/lsconvert.py rename to src/lsconvert.py diff --git a/src/lsconvert/__init__.py b/src/lsconvert/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/jqlcomposer/__init__.py b/tests/__init__.py similarity index 100% rename from src/jqlcomposer/__init__.py rename to tests/__init__.py diff --git a/test/expect1.txt b/tests/expect1.txt similarity index 100% rename from test/expect1.txt rename to tests/expect1.txt diff --git a/test/test1.json b/tests/test1.json similarity index 100% rename from test/test1.json rename to tests/test1.json diff --git a/test/test_jqlcomposer.py b/tests/test_jqlcomposer.py similarity index 69% rename from test/test_jqlcomposer.py rename to tests/test_jqlcomposer.py index a996da7..adb773b 100644 --- a/test/test_jqlcomposer.py +++ b/tests/test_jqlcomposer.py @@ -1,4 +1,3 @@ -from jqlcomposer import jqlcomposer import subprocess import filecmp @@ -8,7 +7,7 @@ def test_jqlcomposer_main_asfile(): for i in range(len(TEST_TERMS)): idx = i+1 with open(f"testout{idx}.txt", "w") as outfile: - subprocess.run(["python", "jqlcomposer.py", TEST_TERMS[i], "--filename", f"test{idx}.json"], stdout=outfile) + subprocess.run(["python", "src/jqlcomposer.py", TEST_TERMS[i], "--filename", f"test{idx}.json"], stdout=outfile) assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") def test_jqlcomposer_main_astext(): @@ -18,6 +17,6 @@ def test_jqlcomposer_main_astext(): with open(f"test{idx}.json", "r") as infile: json_contents = infile.read() with open(f"testout{idx}.txt", "w") as outfile: - subprocess.run(["python", "jqlcomposer.py", TEST_TERMS[i], f'"{json_contents}"'], stdout=outfile) + subprocess.run(["python", "src/jqlcomposer.py", TEST_TERMS[i], f'"{json_contents}"'], stdout=outfile) assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") From e032e4c27b59f59bb6ae6cab163102db868c22ac Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 21:04:04 +0200 Subject: [PATCH 13/15] fix file paths. hopefully. --- tests/test_jqlcomposer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_jqlcomposer.py b/tests/test_jqlcomposer.py index adb773b..b01dff1 100644 --- a/tests/test_jqlcomposer.py +++ b/tests/test_jqlcomposer.py @@ -6,17 +6,17 @@ def test_jqlcomposer_main_asfile(): for i in range(len(TEST_TERMS)): idx = i+1 - with open(f"testout{idx}.txt", "w") as outfile: - subprocess.run(["python", "src/jqlcomposer.py", TEST_TERMS[i], "--filename", f"test{idx}.json"], stdout=outfile) - assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") + with open(f"tests/testout{idx}.txt", "w") as outfile: + subprocess.run(["python", "src/jqlcomposer.py", TEST_TERMS[i], "--filename", f"tests/test{idx}.json"], stdout=outfile) + assert 0 == filecmp.cmp(f"tests/testout{idx}.txt", f"tests/expect{idx}.txt") def test_jqlcomposer_main_astext(): for i in range(len(TEST_TERMS)): idx = i+1 json_contents = "" - with open(f"test{idx}.json", "r") as infile: + with open(f"tests/test{idx}.json", "r") as infile: json_contents = infile.read() - with open(f"testout{idx}.txt", "w") as outfile: + with open(f"tests/testout{idx}.txt", "w") as outfile: subprocess.run(["python", "src/jqlcomposer.py", TEST_TERMS[i], f'"{json_contents}"'], stdout=outfile) - assert 0 == filecmp.cmp(f"testout{idx}.txt", f"expect{idx}.txt") + assert 0 == filecmp.cmp(f"tests/testout{idx}.txt", f"tests/expect{idx}.txt") From 027a9f36397934c95614c89428069225a0549474 Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 21:15:56 +0200 Subject: [PATCH 14/15] add tests for functions - let's see if the import works now --- tests/test_jqlcomposer.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_jqlcomposer.py b/tests/test_jqlcomposer.py index b01dff1..d112bc4 100644 --- a/tests/test_jqlcomposer.py +++ b/tests/test_jqlcomposer.py @@ -1,5 +1,7 @@ import subprocess import filecmp +import jqlcomposer +import contextlib TEST_TERMS=["summer"] @@ -20,3 +22,36 @@ def test_jqlcomposer_main_astext(): subprocess.run(["python", "src/jqlcomposer.py", TEST_TERMS[i], f'"{json_contents}"'], stdout=outfile) assert 0 == filecmp.cmp(f"tests/testout{idx}.txt", f"tests/expect{idx}.txt") +def test_jqlcomposer_compose_from_file(): + for i in range(len(TEST_TERMS)): + idx = i+1 + with open(f"tests/testout{idx}.txt", "w") as outfile: + with contextlib.redirect_stdout(outfile): + jqlcomposer.create_from_file(f"tests/test{idx}.json", TEST_TERMS[i]) + assert 0 == filecmp.cmp(f"tests/testout{idx}.txt", f"tests/expect{idx}.txt") + +def test_jqlcomposer_compose_from_string(): + for i in range(len(TEST_TERMS)): + idx = i+1 + json_contents = "" + with open(f"tests/test{idx}.json", "r") as infile: + json_contents = infile.read() + with open(f"tests/testout{idx}.txt", "w") as outfile: + with contextlib.redirect_stdout(outfile): + jqlcomposer.create_from_string(json_contents, TEST_TERMS[i]) + assert 0 == filecmp.cmp(f"tests/testout{idx}.txt", f"tests/expect{idx}.txt") + +def test_cut_next(): + is_token, next_slice, remainder = jqlcomposer.cut_next("if in {doubt}, flail about") + assert not is_token + assert next_slice == "if in " + assert remainder == "{doubt}, flail about" + is_token, next_slice, remainder = jqlcomposer.cut_next("{doubt} leads to hostility") + assert is_token + assert next_slice == "doubt" + assert remainder == " leads to hostility" + is_token, next_slice, remainder = jqlcomposer.cut_next("nothing to cut here") + assert not is_token + assert next_slice == "nothing to cut here" + assert remainder == "" + \ No newline at end of file From e82057ce339a274c02d5ab427130459b65b96a2e Mon Sep 17 00:00:00 2001 From: starturtle <27267274+starturtle@users.noreply.github.com> Date: Fri, 4 Jul 2025 21:31:39 +0200 Subject: [PATCH 15/15] try with an ini file --- tests/pytest.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/pytest.ini diff --git a/tests/pytest.ini b/tests/pytest.ini new file mode 100644 index 0000000..b893048 --- /dev/null +++ b/tests/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +pythonpath = src \ No newline at end of file