Skip to content

Start testing the scripts using autotests #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -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 --import-mode=importlib
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 <chests>, <stacks>, <items>
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
# will return the tuple of <chests>, <stacks>, <items>
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=",")
5 changes: 0 additions & 5 deletions jqlcomposer/sample.json

This file was deleted.

Empty file added src/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
Empty file added src/minecraft/__init__.py
Empty file.
File renamed without changes.
Empty file added tests/__init__.py
Empty file.
1 change: 1 addition & 0 deletions tests/expect1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
("month IN (June, July, August)") AND (temperature > 20)
2 changes: 2 additions & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
pythonpath = src
5 changes: 5 additions & 0 deletions tests/test1.json
Original file line number Diff line number Diff line change
@@ -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"
}
57 changes: 57 additions & 0 deletions tests/test_jqlcomposer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import subprocess
import filecmp
import jqlcomposer
import contextlib

TEST_TERMS=["summer"]

def test_jqlcomposer_main_asfile():
for i in range(len(TEST_TERMS)):
idx = i+1
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"tests/test{idx}.json", "r") as infile:
json_contents = infile.read()
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"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 == ""

Loading