Пример #1
0
 def test(self, scenario):
     if scenario not in self.actions:
         raise ValueError('"{}" is an invalid scenario'.format(scenario))
     else:
         success, message = self.actions[scenario]
         message = '"{}" is {}: {} was "{}"'.format(
             scenario, 'not invalid' if not success else 'valid',
             'error' if not success else 'message', message)
         print_error(message) if not success else print_success(message)
Пример #2
0
 def test(self, scenario):
     if scenario not in self.actions:
         raise ValueError('"{}" is an invalid scenario'.format(scenario))
     else:
         success, message = self.actions[scenario]
         message = '"{}" is {}: {} was "{}"'.format(
             scenario, 'not invalid' if not success else 'valid',
             'error' if not success else 'message', message)
         print_error(message) if not success else print_success(message)
Пример #3
0
 def process(self, key):
     if len(self.table1) < key:
         raise IndexError('Invalid key for first table!')
     try:
         _key = self.table2[key]
         print_success('Here is the control statement '
                       'you requested: `{}` => `{}`'.format(key, _key))
         return _key
     except IndexError:
         print_error('Could not process key: {}'.format(key))
         return None
Пример #4
0
 def process(self, key):
     if len(self.table1) < key:
         raise IndexError('Invalid key for first table!')
     try:
         _key = self.table2[key]
         print_success('Here is the control statement '
                       'you requested: `{}` => `{}`'.format(key, _key))
         return _key
     except IndexError:
         print_error('Could not process key: {}'.format(key))
         return None
Пример #5
0
 def test(self, string):
     try:
         print_info('{}'.format(string), prefix='[TESTING]')
         chars = list(str(string))
         for char in chars:
             self.step += 1
             self.transition(char)
         self.reset()
         print_success(''.join(chars), prefix='[FOUND]')
         return True
     except InvalidTransition:
         print_error(''.join(chars), prefix='[NOT-FOUND]')
         return False
Пример #6
0
def on_open(ch, method, properties, body):
    key = method.routing_key
    message = '* Received! {}'.format(body)
    if key == 'info':
        print_info(message)
    if key == 'warning':
        print_warning(message)
    if key == 'error':
        print_error(message)
    if key == 'success':
        print_success(message)

    if not start.USE_EXCHANGE:
        # Specify ACK to prevent failures from disappearing.
        ch.basic_ack(delivery_tag=method.delivery_tag)
Пример #7
0
def on_open(ch, method, properties, body):
    key = method.routing_key
    message = '* Received! {}'.format(body)
    if key == 'info':
        print_info(message)
    if key == 'warning':
        print_warning(message)
    if key == 'error':
        print_error(message)
    if key == 'success':
        print_success(message)

    if not start.USE_EXCHANGE:
        # Specify ACK to prevent failures from disappearing.
        ch.basic_ack(delivery_tag=method.delivery_tag)
Пример #8
0
        """INSERT INTO people(name, email, address)
            VALUES (%(name)s, %(email)s, %(address)s)""", peeps)


if DEBUG:
    with Section('PostgreSQL (via psycopg2)'):
        # Starting postgresql on mac:
        # `postgres -D /usr/local/var/postgres/data`
        try:
            conn = psycopg2.connect(dbname='ctabor',
                                    user='******',
                                    host='localhost',
                                    password='')
            print_success('Successfully connected!')
        except:
            print_error('Could not connect to PostgreSql :(')
            raise Exception

        cur = conn.cursor()
        # Always clean up DB for this demo.
        cur.execute("""DROP TABLE people""")
        cur.execute("""CREATE TABLE people(id serial PRIMARY KEY,
            name varchar, email varchar, address varchar)""")

        print_h2('Adding a bunch of records...')
        run_trials(insert_all, trials=10)
        conn.commit()

        print_h2('Reading all records...')

        cur.execute('SELECT * FROM people;')
Пример #9
0
    peeps = [make_person() for n in range(max_records)]
    prnt('Records to create', peeps)
    cur.executemany("""INSERT INTO people(name, email, address)
            VALUES (%(name)s, %(email)s, %(address)s)""", peeps)


if DEBUG:
    with Section('PostgreSQL (via psycopg2)'):
        # Starting postgresql on mac:
        # `postgres -D /usr/local/var/postgres/data`
        try:
            conn = psycopg2.connect(
                dbname='ctabor', user='******', host='localhost', password='')
            print_success('Successfully connected!')
        except:
            print_error('Could not connect to PostgreSql :(')
            raise Exception

        cur = conn.cursor()
        # Always clean up DB for this demo.
        cur.execute("""DROP TABLE people""")
        cur.execute("""CREATE TABLE people(id serial PRIMARY KEY,
            name varchar, email varchar, address varchar)""")

        print_h2('Adding a bunch of records...')
        run_trials(insert_all, trials=10)
        conn.commit()

        print_h2('Reading all records...')

        cur.execute('SELECT * FROM people;')
Пример #10
0
        self.registers[reg] = val


if __name__ == '__main__':
    with Section('Counter Machines'):
        classes = [
            SheperdsonSturgis, Minsky, Program, Abacus, Lambek,
            Successor, SuccessorRAM, ElgotRobinsonRASP,
        ]

        for klass in classes:
            prnt('Testing machine...', repr(klass))
            klass().run()

            cmd_title('New program')
            singleton = CounterMachine()
            singleton._generate_program()
            ppr(singleton.program)
            try:
                singleton.run()
            except TypeError:
                print('Inoperable program was generated :(')
            except NotImplementedError:
                print_error('Not implemented: {}'.format(klass))
            finally:
                singleton.halt()

        print_h2('Random Access Machine (multi-register counter machine)')
        ram = RandomAccessMachine()
        ram.run()
Пример #11
0
from MOAL.helpers.display import Section
from MOAL.helpers.display import print_success
from MOAL.helpers.display import print_error
from MOAL.helpers.display import print_simple
from itertools import permutations

DEBUG = True if __name__ == '__main__' else False


def bigrams(conditions):
    _bigrams = []
    for k, condition in enumerate(conditions):
        if k < len(conditions) - 1:
            _bigrams.append([conditions[k + 1], condition, True, False])
            _bigrams.append([conditions[k + 1], condition, True, True])
            _bigrams.append([conditions[k + 1], condition, False, True])
            _bigrams.append([conditions[k + 1], condition, False, False])
    return _bigrams


if DEBUG:
    with Section('All-pairs testing'):
        conditions = ['user', 'email', 'pass', 'pass2']
        perms = [p for p in permutations(conditions)]
        print_simple('Long way', perms, newline=False)
        print_error('Length: {}'.format(len(perms)), prefix='[LONG]')

        bgrams = bigrams(conditions)
        print_simple('Short (all-pairs) way', bgrams, newline=False)
        print_success('Length: {}'.format(len(bgrams)), prefix='[SHORT]')