def homepage():
    __formattedHtml = ""
    if request.method == 'POST':
        link = request.form['link']
        parser = Parser()
        __parsedParameters = parser.parse_product_parameter(link)
        __formattedHtml = format_table_for_shop(__parsedParameters)

    return render_template('page.html', generatedTable=__formattedHtml)
    def test_CSV_parse(self):
        """Test if parsing CSV works fine (headers do not count and will fail)
        :return:
        """
        stream = Parser("chess-players.csv")

        self.assertGreater(len(stream.list), 0)
    def test_ENOENT(self):
        """Test if class gracefully handles files not found (silently fail to empty lists are okay)
        :return:
        """
        stream = Parser("_chess-players.csv")

        self.assertFalse(stream.list)
Exemplo n.º 4
0
def initialise(filepath):
    """
    Initialises program to encapsulate processing of csv file
    :param filepath: File path to valid csv file containing valid data
    :return: List of chess players in Players object
    """
    csv = Parser(filepath)
    players = []

    # Create Player objects from CSV
    for player in csv.list:
        players.append(Player(player[0], player[1], player[2], player[3], player[4], player[5]))

    # Sort Player objects
    return merge_sort(players)
 def test_xml_file_path_relative_path(self):
     parser = Parser('empty.co', 'commands.xml')
     self.assertEqual(parser.xml_file_path, path.join(self.xml_file_path_directory, 'commands.xml')), \
         'test_xml_file_path_relative_path'
Exemplo n.º 6
0
 def test_unique_words_sample2(self):
     parser = Parser()
     result = parser.get_unique_words("hola si is no no casa casa casa")
     self.assertEqual(5, result)
 def test_evaluate_body_values_mix(self):
     self.assertEqual(Parser.evaluate_body_values(self.expression_list_mix), ['string', True, 5]), \
         'test_value_evaluation_mix'
 def test_evaluate_body_values_ints(self):
     self.assertEqual(
         Parser.evaluate_body_values(self.expression_list_ints),
         [3, 4]), 'test_value_evaluation_ints'
 def test_get_list_elements_type_bool_value(self):
     self.assertEqual(Parser.get_list_elements_type(self.expression_list_bool), [str, bool]), \
         'test_get_list_elements_type_bool_value'
 def test_get_list_elements_type_int_value(self):
     self.assertEqual(Parser.get_list_elements_type(self.expression_list_int), [str, int]), \
         'test_get_list_elements_type_int_value'
 def test_get_list_elements_type_str_value(self):
     self.assertEqual(Parser.get_list_elements_type(self.expression_list_str), [str]), \
         'test_get_list_elements_type_str_value'
 def test_get_list_elements_type_empty_list(self):
     self.assertEqual(Parser.get_list_elements_type([]),
                      []), 'test_get_list_elements_type_empty_list'
Exemplo n.º 13
0
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'

from app.Grapher import Grapher
from app.Lexer import Lexer
from app.Parser import Parser

test_id = 1
# path = f'{getcwd()}/data/pas/test{test_id}.pas'
path = f'{getcwd()}/data/pas2/{test_id}/src.pas'

with open(path, 'r') as source:

    text = source.read()
    lexer = Lexer(text)
    tokens = lexer.lex()

    parser = Parser(tokens)
    ast = parser.parse()
    print(ast)

    symbolizer = Symbolizer(ast)
    symbolizer.symbolize()

    grapher = Grapher(ast)
    img = grapher.graph()

    generator = Generator(ast)
    code = generator.generate('main.c')

Image(img)
Exemplo n.º 14
0
 def test_unique_words(self):
     parser = Parser()
     result = parser.get_unique_words("hola si is no no")
     self.assertEqual(4, result)
Exemplo n.º 15
0
 def test_most_repeated_word(self):
     parser = Parser()
     result = parser.get_most_reapeated_word(
         "hola si is no no casa casa casa")
     self.assertEqual("casa", result)
 def test_evaluate_body_values_basic_value(self):
     self.assertEqual(Parser.evaluate_body_values(self.expression_list_basic), ['variable_name', 3]), \
         'test_value_evaluation_basic_value'
 def test_evaluate_body_values_empty_list(self):
     self.assertEqual(Parser.evaluate_body_values(self.expression_list_empty_list), []), \
         'test_value_evaluation_empty_list'
 def test_xml_file_path_absolute_path_does_not_exist(self):
     with self.assertRaises(Exception) as context:
         Parser('empty.co', path.join(self.xml_file_path_directory, 'no_directory/commands.xml'))
     self.assertEqual(type(context.exception), FileNotFoundError), 'test_xml_file_path_absolute_path_does_not_exist'
 def test_evaluate_body_values_bools(self):
     self.assertEqual(Parser.evaluate_body_values(self.expression_list_bool), [True, False]), \
         'test_value_evaluation_bools'
 def test_xml_file_path_in_directory(self):
     parser = Parser('empty.co', 'directory/commands.xml')
     self.assertEqual(parser.xml_file_path, path.join(self.xml_file_path_directory, 'directory', 'empty.xml')), \
         'test_xml_file_path_in_directory'
Exemplo n.º 21
0
#! /usr/bin/python2.7

from flask import Flask, render_template, request
from app.Article import Article
from app.DB import DB
from app.Parser import Parser

app = Flask(__name__)
app.config["DEBUG"] = True  # Only include this while you are testing your app

# Initialize db
db = DB(purge=False)

# Initialize parser
parser = Parser(db)

# Initialize watch list
watch_list = []


@app.route("/", methods=['GET'])
def get_watchlist():
    if watch_list:
        art = db.get_articles(watch_list)
    else:
        global watch_list
        watch_list = list(set(watch_list))
        art = db.get_general_articles()

    print watch_list
    return render_template('layout.html', articles=art)
 def test_xml_file_path_double_dot(self):
     chdir('directory')
     parser = Parser('empty.co', '../commands.xml')
     self.assertEqual(parser.xml_file_path, path.join(self.xml_file_path_directory, 'commands.xml')), \
         'test_xml_file_path_double_dot'