Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ celerybeat-schedule
.env

# Spyder project settings
.spyderproject
.spyderproject
pyproject.toml
uv.lock
.DS_Store
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'tracery',
],
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
install_requires=[],
install_requires=['pyjson5>=1.6.7'],
license="Apache License 2.0",
zip_safe=True,
keywords='tracery',
Expand Down
29 changes: 29 additions & 0 deletions tests/test_grammar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// json5 supports comments

{
'deepHash': ["\\#00FF00", "\\#FF00FF"],
'deeperHash': ["#deepHash#"],
'animal': ["bear", "cat", "dog", "fox", "giraffe", "hippopotamus"],
'mood': ["quiet", "morose", "gleeful", "happy", "bemused", "clever",
"jovial", "vexatious", "curious", "anxious", "obtuse", "serene",
"demure"],
'nonrecursiveStory': ["The #pet# went to the beach."],
'recursiveStory': [
"The #pet# opened a book about[pet:#mood# #animal#] #pet.a#. #story#[pet:POP] The #pet# closed the book."],
'svgColor': ["rgb(120,180,120)", "rgb(240,140,40)", "rgb(150,45,55)",
"rgb(150,145,125)", "rgb(220,215,195)", "rgb(120,250,190)"],
'svgStyle': ['style="fill:#svgColor#;stroke-width:3;stroke:#svgColor#"'],
"name": ["Cheri", "Fox", "Morgana", "Jedoo", "Brick", "Shadow", "Krox",
"Urga", "Zelph"],
"story": ["#hero.capitalize# was a great #occupation#, and this song tells of #heroTheir# adventure. #hero.capitalize# #didStuff#, then #heroThey# #didStuff#, then #heroThey# went home to read a book."],
"monster": ["dragon", "ogre", "witch", "wizard", "goblin", "golem",
"giant", "sphinx", "warlord"],
"setPronouns": [
"[heroThey:they][heroThem:them][heroTheir:their][heroTheirs:theirs]",
"[heroThey:she][heroThem:her][heroTheir:her][heroTheirs:hers]",
"[heroThey:he][heroThem:him][heroTheir:his][heroTheirs:his]"],
"setOccupation": [
"[occupation:baker][didStuff:baked bread,decorated cupcakes,folded dough,made croissants,iced a cake]",
"[occupation:warrior][didStuff:fought #monster.a#,saved a village from #monster.a#,battled #monster.a#,defeated #monster.a#]"],
"origin": ["#[#setPronouns#][#setOccupation#][hero:#name#]story#"]
}
39 changes: 5 additions & 34 deletions tests/test_tracery.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,15 @@
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))

import pyjson5

import tracery
from tracery.modifiers import base_english


test_grammar = {
'deepHash': ["\\#00FF00", "\\#FF00FF"],
'deeperHash': ["#deepHash#"],
'animal': ["bear", "cat", "dog", "fox", "giraffe", "hippopotamus"],
'mood': ["quiet", "morose", "gleeful", "happy", "bemused", "clever",
"jovial", "vexatious", "curious", "anxious", "obtuse", "serene",
"demure"],
'nonrecursiveStory': ["The #pet# went to the beach."],
'recursiveStory': [
"The #pet# opened a book about[pet:#mood# #animal#] #pet.a#. "
"#story#[pet:POP] The #pet# closed the book."],
'svgColor': ["rgb(120,180,120)", "rgb(240,140,40)", "rgb(150,45,55)",
"rgb(150,145,125)", "rgb(220,215,195)", "rgb(120,250,190)"],
'svgStyle': ['style="fill:#svgColor#;stroke-width:3;stroke:#svgColor#"'],
"name": ["Cheri", "Fox", "Morgana", "Jedoo", "Brick", "Shadow", "Krox",
"Urga", "Zelph"],
"story": ["#hero.capitalize# was a great #occupation#, and this song "
"tells of #heroTheir# adventure. #hero.capitalize# #didStuff#, "
"then #heroThey# #didStuff#, then #heroThey# went home "
"to read a book."],
"monster": ["dragon", "ogre", "witch", "wizard", "goblin", "golem",
"giant", "sphinx", "warlord"],
"setPronouns": [
"[heroThey:they][heroThem:them][heroTheir:their][heroTheirs:theirs]",
"[heroThey:she][heroThem:her][heroTheir:her][heroTheirs:hers]",
"[heroThey:he][heroThem:him][heroTheir:his][heroTheirs:his]"],
"setOccupation": [
"[occupation:baker][didStuff:baked bread,decorated cupcakes,"
"folded dough,made croissants,iced a cake]",
"[occupation:warrior][didStuff:fought #monster.a#,saved a village "
"from #monster.a#,battled #monster.a#,defeated #monster.a#]"],
"origin": ["#[#setPronouns#][#setOccupation#][hero:#name#]story#"]
}

with open('tests/test_grammar.json') as data_file:
"""We'll open the test grammar as a file now, instead of having it inline"""
test_grammar = pyjson5.decode_io(data_file)

class TestPytracery(unittest.TestCase):
"""Common setUp and helpers"""
Expand Down
4 changes: 2 additions & 2 deletions tracery/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from __future__ import print_function, unicode_literals
import argparse
import json
import pyjson5

import tracery
from tracery.modifiers import base_english
Expand All @@ -22,7 +22,7 @@
args = parser.parse_args()

with open(args.json) as data_file:
rules = json.load(data_file)
rules = pyjson5.decode_io(data_file)

grammar = tracery.Grammar(rules)
grammar.add_modifiers(base_english)
Expand Down