Skip to content
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

Ratchet #3

Merged
merged 2 commits into from
May 11, 2022
Merged
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
1 change: 0 additions & 1 deletion forthic/global_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from typing import Optional, Union, Any, List


DLE = chr(16) # ASCII DLE char


Expand Down
1,770 changes: 885 additions & 885 deletions tests/tests_py/modules/confluence_context.py

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions tests/tests_py/modules/jira_context.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import json
from forthic.modules.jira_module import JiraContext


class ServerResponse:
def __init__(self, string, status_code=200):
self.json_string = string
self.status_code = status_code
self.text = ""
self.ok = status_code < 300

def json(self):
result = json.loads(self.json_string)
return result



class JiraTestContext(JiraContext):
def get_host(self):
return "http://testcontext"
Expand Down Expand Up @@ -55,14 +55,22 @@ def requests_put(self, api_url, json=None, session=None):


REST_API_2_FIELD_RESPONSE = '''
[{"id":"issuekey","name":"Key","custom":false,"orderable":false,"navigable":true,"searchable":false,"clauseNames":["id","issue","issuekey","key"]},
{"id":"assignee","name":"Assignee","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["assignee"],"schema":{"type":"user","system":"assignee"}},
{"id":"summary","name":"Summary","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["summary"],"schema":{"type":"string","system":"summary"}},
{"id":"project","name":"Project","custom":false,"orderable":false,"navigable":true,"searchable":true,"clauseNames":["project"],"schema":{"type":"project","system":"project"}},
{"id":"reporter","name":"Reporter","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["reporter"],"schema":{"type":"user","system":"reporter"}},
{"id":"issuetype","name":"Issue Type","custom":false,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["issuetype","type"],"schema":{"type":"issuetype","system":"issuetype"}},
{"id":"customfield_10460","name":"Risk_Factor","custom":true,"orderable":true,"navigable":true,"searchable":true,"clauseNames":["cf[10460]","Risk_Factor"],"schema":{"type":"option","custom":"com.atlassian.jira.plugin.system.customfieldtypes:select","customId":10460}},
{"id":"timespent","name":"Time Spent","custom":false,"orderable":false,"navigable":true,"searchable":false,"clauseNames":["timespent"],"schema":{"type":"number","system":"timespent"}}]
[{"id":"issuekey","name":"Key","custom":false,"orderable":false,"navigable":true,"searchable":false,
"clauseNames":["id","issue","issuekey","key"]},
{"id":"assignee","name":"Assignee","custom":false,"orderable":true,"navigable":true,"searchable":true,
"clauseNames":["assignee"],"schema":{"type":"user","system":"assignee"}},
{"id":"summary","name":"Summary","custom":false,"orderable":true,"navigable":true,"searchable":true,
"clauseNames":["summary"],"schema":{"type":"string","system":"summary"}},
{"id":"project","name":"Project","custom":false,"orderable":false,"navigable":true,"searchable":true,
"clauseNames":["project"],"schema":{"type":"project","system":"project"}},
{"id":"reporter","name":"Reporter","custom":false,"orderable":true,"navigable":true,"searchable":true,
"clauseNames":["reporter"],"schema":{"type":"user","system":"reporter"}},
{"id":"issuetype","name":"Issue Type","custom":false,"orderable":true,"navigable":true,"searchable":true,
"clauseNames":["issuetype","type"],"schema":{"type":"issuetype","system":"issuetype"}},
{"id":"customfield_10460","name":"Risk_Factor","custom":true,"orderable":true,"navigable":true,"searchable":true,
"clauseNames":["cf[10460]","Risk_Factor"],"schema":{"type":"option","custom":"com.atlassian.jira.plugin.system.customfieldtypes:select","customId":10460}},
{"id":"timespent","name":"Time Spent","custom":false,"orderable":false,"navigable":true,"searchable":false,
"clauseNames":["timespent"],"schema":{"type":"number","system":"timespent"}}]
'''

SEARCH_RESPONSE1 = '''
Expand Down
3 changes: 2 additions & 1 deletion tests/tests_py/modules/test_confluence_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ def test_UPSERT_PAGE(self):
""")

def test_pipe_ESCAPE_TABLE_CONTENT2(self):
self.interp.run("""
self.interp.run("""
'+*Q2 Objectives*+\r\n\r\nReduce tech debts, operational burdens and cost-to-serve' |ESCAPE-TABLE-CONTENT
""")
assert(self.interp.stack[0] == '+*Q2 Objectives*+\nReduce tech debts, operational burdens and cost-to-serve')


if __name__ == '__main__':
unittest.main()
3 changes: 2 additions & 1 deletion tests/tests_py/modules/test_html_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def get_interp():
result.run('[["html" ""]] USE-MODULES')
return result


class TestHtmlModule(unittest.TestCase):
def setUp(self):
self.interp = get_interp()
Expand Down Expand Up @@ -45,7 +46,7 @@ def test_child_nodes(self):
row @ CHILD-NODES LENGTH
""")
stack = self.interp.stack
self.assertEqual([1, True, 3], self.interp.stack)
self.assertEqual([1, True, 3], stack)

def test_node_content(self):
self.interp.run("""
Expand Down
6 changes: 4 additions & 2 deletions tests/tests_py/modules/test_jira_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ def test_FIELD_AS_OF_SINCE(self):

# NOTE: Here is the changelog
# [{'date': datetime.datetime(2020, 7, 25, 1, 36, 24, tzinfo=tzutc()), 'field': 'Risk_Factor', 'from': '', 'to': 'Blue'},
# {'date': datetime.datetime(2020, 7, 25, 1, 38, 46, tzinfo=tzutc()), 'field': 'Risk_Factor', 'from': 'Blue', 'to': 'Green', 'from_': '32078', 'to_': '32075'},
# {'date': datetime.datetime(2020, 8, 15, 1, 39, 5, tzinfo=tzutc()), 'field': 'Risk_Factor', 'from': 'Green', 'to': 'Yellow', 'from_': '32078', 'to_': '32075'}]
# {'date': datetime.datetime(2020, 7, 25, 1, 38, 46, tzinfo=tzutc()), 'field': 'Risk_Factor',
# 'from': 'Blue', 'to': 'Green', 'from_': '32078', 'to_': '32075'},
# {'date': datetime.datetime(2020, 8, 15, 1, 39, 5, tzinfo=tzutc()), 'field': 'Risk_Factor',
# 'from': 'Green', 'to': 'Yellow', 'from_': '32078', 'to_': '32075'}]

2020-07-25 changes @ "Risk_Factor" 2020-07-01 jira.FIELD-AS-OF-SINCE
2020-10-01 changes @ "Risk_Factor" 2020-07-01 jira.FIELD-AS-OF-SINCE
Expand Down
7 changes: 3 additions & 4 deletions tests/tests_py/modules/test_org_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ def test_GROUP_BY_LEADS(self):
items = [
{"key": 101, "owner": "user101"},
{"key": 102, "owner": "user102"},

{"key": 202, "owner": "user202"},
{"key": 203, "owner": "user203"},
{"key": 302, "owner": "mgr2"},

{"key": 401, "owner": "user401"},
]

Expand Down Expand Up @@ -87,6 +85,7 @@ def test_CHAIN_KEY_FUNC(self):
self.interp.run("['user101' 'mgr1' 'user203' 'director1'] 'vp1' org.CHAIN-KEY-FUNC SORT-w/KEY-FUNC")
self.assertEqual(['director1', 'mgr1', 'user101', 'user203'], self.interp.stack[0])


def get_context():
def get_users_managers():
res = [
Expand All @@ -96,8 +95,8 @@ def get_users_managers():
["user201", "mgr2"],
["user202", "mgr2"],
["user203", "mgr2"],
["mgr1", "director1"],
["mgr2", "director1"],
["mgr1", "director1"],
["mgr2", "director1"],
["director1", "vp1"]
]
return res
Expand Down
12 changes: 4 additions & 8 deletions tests/tests_py/test_global_module.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from operator import index
import unittest
import datetime
import pytz
from forthic.interpreter import Interpreter, UnknownWordError
from forthic.tokenizer import DLE
from forthic.global_module import GlobalModuleError


class TestGlobalModule(unittest.TestCase):
def test_literal(self):
interp = Interpreter()
Expand Down Expand Up @@ -114,11 +114,11 @@ def test_memo(self):
self.assertEqual(interp.stack[-1], 1)

interp.run("COUNT! COUNT")
self.assertEqual(interp.stack[-1] , 2)
self.assertEqual(interp.stack[-1], 2)
self.assertEqual(len(interp.stack), 3)

interp.run("COUNT!@")
self.assertEqual(interp.stack[-1] , 3)
self.assertEqual(interp.stack[-1], 3)

def test_rec(self):
interp = Interpreter()
Expand All @@ -139,7 +139,7 @@ def test_rec_at(self):
'beta' REC@
""")
self.assertEqual(len(interp.stack), 1)
self.assertEqual(interp.stack[0] , 3)
self.assertEqual(interp.stack[0], 3)

def test_l_rec_bang(self):
# Case: Set value on a record
Expand Down Expand Up @@ -242,7 +242,6 @@ def test_reverse(self):
self.assertEqual(len(interp.stack), 1)
self.assertEqual(list(interp.stack[-1].keys()), ["b", "a"])


def test_unique(self):
interp = Interpreter()
interp.run("""
Expand Down Expand Up @@ -777,7 +776,6 @@ def test_UNION(self):
self.assertEqual(sorted(list(stack[0].keys())), ['a', 'b', 'c', 'd', 'f'])
self.assertEqual(sorted(list(stack[0].values())), [1, 2, 3, 10, 40])


def test_select(self):
interp = Interpreter()
interp.run("""
Expand Down Expand Up @@ -1134,7 +1132,6 @@ def test_pipe_ascii(self):
stack = interp.stack
self.assertEqual(stack[0], "HOWDY, Everyone!")


def test_strip(self):
interp = Interpreter()
interp.run("""
Expand Down Expand Up @@ -1199,7 +1196,6 @@ def test_URL_DECODE(self):
stack = interp.stack
self.assertEqual(stack[0], "now/is the time")


def test_default(self):
interp = Interpreter()
interp.run("""
Expand Down
7 changes: 1 addition & 6 deletions tests/tests_py/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,30 @@
from forthic.module import Module, ModuleWord
from tests.tests_py.sample_date_module import SampleDateModule


class TestInterpreter(unittest.TestCase):

def test_initial_state(self):
interp = Interpreter()
self.assertEqual(0, len(interp.stack))
self.assertEqual("", interp.module_stack[0].name)


def test_push_string(self):
interp = Interpreter()
interp.run("'Howdy'")
self.assertEqual("Howdy", interp.stack[0])


def test_comment(self):
interp = Interpreter()
interp.run("# A comment")
interp.run("#A comment")
self.assertEqual(0, len(interp.stack))


def test_empty_array(self):
interp = Interpreter()
interp.run("[]")
self.assertEqual([], interp.stack[0])


def test_start_module(self):
interp = Interpreter()

Expand Down Expand Up @@ -62,7 +59,6 @@ def test_start_module(self):
self.assertEqual(1, len(interp.module_stack))
self.assertEqual(interp.module_stack[0], interp.app_module)


def test_definition(self):
# Can define and find a word in the app module
interp = Interpreter()
Expand Down Expand Up @@ -162,7 +158,6 @@ def test_search_global_module(self):
return False
return True


def test_use_module(self):
interp = Interpreter()
interp.register_module(SampleDateModule)
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_py/test_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from forthic.tokens import StringToken, StartArrayToken, EndArrayToken, StartModuleToken,\
EndModuleToken, StartDefinitionToken, EndDefinitionToken, StartMemoToken, WordToken, EOSToken


def get_tokens(tokenizer):
result = []
token = None
Expand Down Expand Up @@ -60,7 +61,6 @@ def test_end_definition(self):
self.assertIsInstance(tokens[1], EndDefinitionToken)
self.assertTrue(is_word_token(tokens[2], "WORD2"))


def test_start_module(self):
tokenizer = Tokenizer("{ {my-mod")
tokens = get_tokens(tokenizer)
Expand Down
3 changes: 1 addition & 2 deletions tests/tests_py/test_tokenizer_errors.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import unittest
from forthic.tokenizer import Tokenizer, UnterminatedStringError, InvalidDefinitionError


class TestTokenizerErrors(unittest.TestCase):
def test_unterminated_string(self):
"""Raise exception if strings are unterminated
"""
tokenizer = Tokenizer("'Unterminated")
self.assertRaises(UnterminatedStringError, tokenizer.next_token)


def test_start_definition_eos(self):
"""Can't have an empty definition
"""
tokenizer = Tokenizer(":")
self.assertRaises(InvalidDefinitionError, tokenizer.next_token)


def test_start_definition_special_chars(self):
"""Can't have definition with Forthic special chars
"""
Expand Down