예제 #1
0
 def test_parse_with_incorrect_number_of_queries(self):
     mock_open = mock.mock_open(read_data=self.INCORRECT_NUMBER_OF_QUERIES_INPUT_FILE)
     with mock.patch('main.open', mock_open, create=True):
         with self.assertRaises(Exception) as e:
             parser = Parser()
             parser.parse('')
     error_msg = e.exception
     self.assertEquals(str(error_msg), Parser.INCORRECT_NUMBER_OF_QUERIES_ERROR_MSG)
예제 #2
0
 def test_parse_with_incorrect_input_file(self):
     mock_open = mock.mock_open(read_data=self.INCORRECT_INPUT_FILE)
     with mock.patch('main.open', mock_open, create=True):
         with self.assertRaises(Exception) as e:
             parser = Parser()
             parser.parse('')
     error_msg = e.exception
     self.assertEquals(str(error_msg), Parser.INCORRECT_FORMAT_OF_FILE_ERROR_MSG)
예제 #3
0
def runtests(amount=1):
    for i in range(amount):
        methods = ['*', '/', '+', '-']
        x = random.randint(-100, 100)
        m = random.choice(methods)
        y = random.randint(-100, 100)
        if y == 0:
            y = 1
        test = f'{x} {m} {y}'
        print(f'Running test on {test}')
        myres = Parser().parse(Lexer().lex(test)).calculate().to_actual_type()
        actualres = eval(test)
        print(myres)
        if myres != actualres:
            raise Exception(f'Results differ, {myres} {actualres}')
예제 #4
0
    def test_parse_correct_input_file(self):
        mock_open = mock.mock_open(read_data=self.CORRECT_INPUT_FILE)
        with mock.patch('main.open', mock_open, create=True):
            parser = Parser()
            parser.parse('')

        self.assertEqual(parser.cases_list.__len__(), 1)
        self.assertEqual(parser.cases_list[0].city.dx, 4)
        self.assertEqual(parser.cases_list[0].city.dy, 4)
        self.assertEquals(parser.cases_list[0].coffee_shops.__len__(), 5)
        self.assertIn((1, 1), parser.cases_list[0].coffee_shops)
        self.assertIn((1, 2), parser.cases_list[0].coffee_shops)
        self.assertIn((3, 3), parser.cases_list[0].coffee_shops)
        self.assertIn((4, 4), parser.cases_list[0].coffee_shops)
        self.assertIn((2, 4), parser.cases_list[0].coffee_shops)
        self.assertEquals(parser.cases_list[0].queries.__len__(), 3)
        self.assertIn(1, parser.cases_list[0].queries)
        self.assertIn(2, parser.cases_list[0].queries)
        self.assertIn(4, parser.cases_list[0].queries)
예제 #5
0
 def setUp(self):
     self.parser = Parser()
예제 #6
0
파일: Example.py 프로젝트: CDog5/AutoUpdate
lexed = lexer.lex("2.2 + 2")
print(lexed.as_raw())
print(lexed.as_tuple())
print(lexed.as_list())
print(lexed.as_dict())

'''

#reads from file and prints line by line results
'''
a=Lexer().lex_lbl('example.txt')
b = Parser().parse_lbl(a)
print(b.ln_res())
'''
#calculator using lexer and parser

while True:
    userinput = input("Calc:")
    parseres = Parser().parse(Lexer().lex(userinput))
    calcres = parseres.calculate()
    if calcres.type != 'RES_SETVAR':
        print(calcres.token)

#Func that returns formatted string
'''
while True:
    a=input("Lex:")
    b = Lexer().lex(a)
    print(b.as_strf('Value: %v Type: %t Pos: (%s,%e)'))
'''
예제 #7
0
from main import encrypt, Lexer, Parser, File

answer = input("""
        Hey Pr0, What you wanna do(?)
        Press 1 for Encrypting text
        Press 2 for Decrypting text
        \n
        """)
if answer == "1":
    text = input("Tell me what you wanna encrypt: ")
    new_l = Lexer(encrypt(text))
    new_l.create_encrypted()
    new_l.create_schema()
    print(new_l.generate_files())
elif answer == "2":
    enc = input("Enter the exact path of the encrypted file: ")
    sch = input("Enter the exact path of the schema file: ")
    dec = Parser(File(enc).read(), File(sch).read())
    print("Here goes the decrypted string" + "\n" +
          "==========================HALO10=============================" +
          "\n" + dec.decrypt())
else:
    print("Simp.. that's an incorrect try")
예제 #8
0
파일: test.py 프로젝트: Den4200/dot
def main():
    with open('app\\tests\\test.do', 'r') as f:
        content = f.read()
    
    tokens = Lexer(content).tokenize()
    Parser(tokens).parse()
예제 #9
0
파일: Example.py 프로젝트: CDog5/Python
from main import Lexer, Parser 
#shows lexer working
'''
lexer = Lexer()
lexed = lexer.lex("2.2 + 2")
print(lexed.as_raw())
print(lexed.as_tuple())
print(lexed.as_list())
print(lexed.as_dict())
'''
#calculator using lexer and parser
'''
while True:
    a=input("Calc:")
    print(Parser().parse(Lexer().lex(a)).calculate().token)
'''
while True:
    a=input("Calc:")
    print(Parser().parse(Lexer().lex(a)).calculate().token)
예제 #10
0
 def test_fake_regular(self):
     regular = '*'
     k = 4
     x = Parser(regular, k)
     with pytest.raises(ParserException):
         x.get_answer(3)
예제 #11
0
 def test_7(self):
     regular = 'aa.bbb..+*'
     k = 10
     x = Parser(regular, k)
     assert [x.get_answer(i)
             for i in range(k)] == [0, 11, 2, 3, 4, 5, 6, 7, 8, 9]
예제 #12
0
 def test_6(self):
     regular = 'ab.'
     k = 4
     x = Parser(regular, k)
     assert [x.get_answer(i) for i in range(k)] == ['INF', 'INF', 2, 'INF']
예제 #13
0
 def test_3(self):
     regular = 'aba.*.a.*ab1+..'
     k = 4
     x = Parser(regular, k)
     assert [x.get_answer(i) for i in range(k)] == [4, 1, 2, 3]
예제 #14
0
 def test_sample_2(self):
     regular = 'acb..bab.c.*.ab.ba.+.+*a.'
     k = 3
     x = Parser(regular, k)
     assert [x.get_answer(i) for i in range(k)] == ['INF', 1, 'INF']
예제 #15
0
 def test_sample_1(self):
     regular = 'ab+c.aba.*.bac.+.+*'
     k = 3
     x = Parser(regular, k)
     assert [x.get_answer(i) for i in range(k)] == [0, 4, 2]
예제 #16
0
from main import Lexer, Parser
#shows lexer working
'''
lexer = Lexer()
lexed = lexer.lex("2.2 + 2")
print(lexed.as_raw())
print(lexed.as_tuple())
print(lexed.as_list())
print(lexed.as_dict())
'''
#calculator using lexer and parser

while True:
    a = input("Calc:")
    b = Parser().parse(Lexer().lex(a))
    print(b.as_raw())
    print(b.calculate().token)

#New func that returns formatted string
'''
while True:
    a=input("Lex:")
    b = Lexer().lex(a)
    print(b.as_strf('Value: %v Type: %t')
'''
예제 #17
0
"""

Example batch script. This one want as input a directory that has txt and fact files.

"""

import os, sys, glob

from main import Parser

INDIR = sys.argv[1]
OUTDIR = 'data/tmp'

for text_file in glob.glob("%s/*.txt" % INDIR):
    basename = os.path.basename(text_file)
    fact_file = text_file[:-3] + 'fact'
    sect_file = os.path.join(OUTDIR, basename[:-3] + 'sect')
    if os.path.exists(fact_file):
        #if not basename == 'USPP021257P2.txt':
        #    continue
        print basename
        parser = Parser()
        parser.collection = 'LEXISNEXIS'
        parser.process_file(text_file, fact_file, sect_file, verbose=False)
예제 #18
0
 def add_to_output(self):
     json_test = dict(id="test", score=12, ip="1.2.3.4", message="Hi")
     parse = Parser()
     parse.add_to_output(json_test)
     self.assertEqual(parse.object_list[-1], json_test)
예제 #19
0
 def products(self):
     xml = minidom.parse("RatesHistory.xml")
     return Parser(xml).parse_products()
예제 #20
0
import sys
from main import Lexer, Parser
from utils import VERSION
##try:
##    tmp = sys.argv[1]
##except:
##    raise Exception("This program is a CLI application only. Please specify args.") from None
##my_text = " ".join(sys.argv[1:])
##l = Lexer().lex(my_text)
##parseres = Parser().parse(l)
##calcres = parseres.calculate()
##print(calcres.token,end="")

if "pythonw.exe" not in sys.executable:
    print(f"CSLang version {VERSION}.")
    while True:
        text = input(">>>")
        if text == "" or text.lower() == "exit":
            break
        l = Lexer().lex(text)
        parseres = Parser().parse(l)
        calcres = parseres.calculate()
        print(calcres.token)
else:
    raise Exception("This program is a CLI application only.") from None