Example #1
0
 def test_loading_non_existing_fixture(self):
     engine = Engine()
     engine.loader = StringLoader('import doesntexist\n')
     try:
         engine.load_fixture('SomeQuery')
     except ImportError, inst:
         pass
Example #2
0
    def __init__(self):
        Engine.__init__(self)

        # Only one dashboard per process
        if Dashboard._single:
            raise Singleton(self)
        Dashboard._single = self
        try:
            self._conf_widgets = Widgets()
        except Singleton as e:
            self._conf_widgets = e.get_singleton()
Example #3
0
    def __init__(self, bot, conf):
        """
        :type bot bot.slack.Bot
        :param conf configparser.ConfigParser
        :return:
        """
        Engine.__init__(self, bot, conf)
        self.bot = bot
        self.conf = conf

        self.bot.add_listener(event.message, self.message_listener)
Example #4
0
    def test_input_table(self):

        engine = Engine()
        engine.loader = StringLoader('import doesntexist\n')

        wiki = '''
            |OccupantList|
            |user |room |
            |anna |lotr |
            |luke |lotr |
        '''

        table = Table(wiki_table_to_plain(wiki))
        engine.process(table, throw=False)
Example #5
0
class TestActionFixture(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()
        self.engine.loader = CreateFixture(globals())

    def process(self, wiki):
        self.table = Table(wiki_table_to_plain(wiki))
        return self.engine.process(self.table)

    def test_existing_attribute(self):
        wiki = '''
            |ActionFixture|
            |start|FakeBuyActions|
        '''
        
        fixture = self.process(wiki)

    def test_existing_attribute2(self):
        wiki = '''
            |ActionFixture|
            |start|FakeBuyActions|
            |check|total|00.00|
        '''
        
        fixture = self.process(wiki)
Example #6
0
    def _edit_engine_name(self, new_index):

        # detect if we try to manually adjust the name
        # if so, we need to reset the current index, overwrite the name and remove the new element
        # make sure to not do this when we created the first element this way
        if new_index >= len(self.engines.engines) and new_index >= 1:
            new_text = self.engine_combo.currentText()
            old_text = self.engine_combo.itemText(self.engine_combo_index)
            self.engine_combo.setItemText(self.engine_combo_index, new_text)
            self.engine_combo.setCurrentIndex(self.engine_combo_index)
            self.engine_combo.removeItem(new_index)

            # also adjusting the name in the config
            self.engines.engines[new_text] = self.engines.engines[old_text]
            del self.engines.engines[old_text]
            updateStatusBar('replaced engine name')
        elif new_index >= len(self.engines.engines) and new_index == 0:
            new_text = self.engine_combo.currentText()
            self.engines.engines[new_text] = Engine()
            self.engine_combo_index = self.engine_combo.currentIndex()
            updateStatusBar('created new engine')
        else:
            self.engine_combo_index = self.engine_combo.currentIndex()
            updateStatusBar('changed current engine')

        self._update_option_widgets()
Example #7
0
    def __init__(self, *a, **k):
        super().__init__(*a, **k)

        # get boxes from story registry, create+store an engine for each
        boxTable = self.story._get_table(Box)
        self.engines = dict()
        for boxUid, box in boxTable.items():
            engine = Engine(box=box)
            engine.registerStory(self.story)
            self.engines[boxUid] = engine

        # for each card, register it with the emulator
        cardIds = "a"
        for cardId in cardIds:
            card = self.story.createBlankCard(cardId)
            self.registerCard(card)

        self.currentCard = None
Example #8
0
    def __init__(self, bot, conf):
        Engine.__init__(self, bot, conf)
        self.commandPrefix = conf["command"]["commandPrefix"]
        self.do_thread = conf["command"]["threading"]

        # register listener
        if self.do_thread:
            print("Enabling threading...")
            self.threads = []
            self.bot.add_listener(event.message, self.create_message_thread)
            self.bot.wait_for_reply = lambda self, ID=0: True  # waiting for reply causes glitches, so we're disabling it
        else:
            self.bot.add_listener(event.message, self.on_any_message)

        # create dict to hold commands
        self.commands = {}

        # get permissions engine from bot
        self.perms = self.bot.enginesSupplied["permission"]
Example #9
0
    def __init__(self, bot, conf):
        Engine.__init__(self, bot, conf)
        self.commandPrefix = conf["command"]["commandPrefix"]
        self.do_thread = conf["command"]["threading"]

        # register listener
        if self.do_thread:
            print("Enabling threading...")
            self.threads = []
            self.bot.add_listener(event.message, self.create_message_thread)
            self.bot.wait_for_reply = lambda self, ID=0: True  # waiting for reply causes glitches, so we're disabling it
        else:
            self.bot.add_listener(event.message, self.on_any_message)

        # create dict to hold commands
        self.commands = {}

        # get permissions engine from bot
        self.perms = self.bot.enginesSupplied["permission"]
Example #10
0
class Client(Protocol):
    def __init__(self):
        self.engine = Engine()
        self.engine.print_traceback = True
        self.proto = FitnesseProtocol(self)

    def ack(self):
        self.ack_received = True

    def connectionMade(self):
        self.socketToken = sys.argv[4]
        request = "GET /?responder=socketCatcher&ticket=%s HTTP/1.1\r\n\r\n" % self.socketToken
        bytes = request.encode("UTF-8")
        self.transport.write(bytes)

    def dataReceived(self, data):
        self.proto.dataReceived(data)

    def content(self, data):
        self.doc = Document(data)
        self.doc.visit_tables(self)

    def on_table(self, table):
        fixture = self.engine.process(table, throw=False)
        self.write_table(table)

    def on_comment(self, node):
        html = str(node.toxml())
        self.transport.write(util.format_10_digit_number(len(html) + 1))
        self.transport.write(html)
        self.transport.write('\n')
    
    def done(self):
        self.transport.loseConnection()
        
    def write_table(self, table):
        html = str(table.toxml()) # Fixme : str() workaround for 'Data must not be unicode'
        self.transport.write(util.format_10_digit_number(len(html) + 1))
        self.transport.write(html)
        self.transport.write('\n')
        
    def write_number(self, number):
        self.transport.write(util.format_10_digit_number(number))

    def report(self):
        summary = self.engine.summary

        # 0 right, 0 wrong, 0 ignored, 0 exceptions
        self.write_number(0)
        self.write_number(summary.right)
        self.write_number(summary.wrong)
        self.write_number(summary.ignored)
        self.write_number(summary.exceptions)
        summary.reset()
Example #11
0
    def _add_engine(self, name=None):

        new_idx = 1
        new_name = f"NewEngine{new_idx}" if name is None else name
        i = 0
        while i < self.engine_combo.count():
            if self.engine_combo.itemText(i) == new_name:
                i = 0
                new_idx += 1
            new_name = f"NewEngine{new_idx}"
            i += 1

        self.engines.engines[new_name] = Engine()
        self.engine_combo.addItem(new_name)
        self.engine_combo.setCurrentIndex(self.engine_combo.count() - 1)
        self.engine_combo_index = self.engine_combo.count() - 1
Example #12
0
class TestRowFixture2(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()
        self.engine.loader = CreateFixture(globals())

    def process(self, wiki):
        self.table = Table(wiki_table_to_plain(wiki))
        return self.engine.process(self.table)

    def test_passing_table(self):
        wiki = '''
            |OccupantList|
            |user |room |
            |anna |lotr |
            |luke |lotr |
        '''

        fixture = self.process(wiki)
        self.assertEqual(fixture.differ.missing, [])
        self.assertEqual(fixture.differ.surplus, [])

    def test_one_missing_row(self):
        wiki = '''
            |OccupantList|
            |user |room |
            |anna |lotr |
            |luke |lotr |
            |bob  |lotr |
        '''

        fixture = self.process(wiki)
        self.assertEqual(fixture.differ.missing, [[Cell('bob'), Cell('lotr')]])
        self.assertEqual(fixture.differ.surplus, [])
        self.assert_(self.table.cell(0,4).is_missing)

    def test_one_surplus_row(self):
        wiki = '''
            |OccupantList|
            |user |room |
            |anna |lotr |
        '''

        fixture = self.process(wiki)
        self.assertEqual(fixture.differ.missing, [])
        self.assertEqual(fixture.differ.surplus, [['luke', 'lotr']])
        self.assertEqual(len(self.table.rows), 4)
Example #13
0
class TestActionFixture(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()
        self.engine.loader = CreateFixture(globals())

    def process(self, wiki):
        self.table = Table(wiki_table_to_plain(wiki))
        return self.engine.process(self.table)

    def _test_existing_attribute(self):
        wiki = '''
            |ActionFixture|
            |start|FakeBuyActions|
        '''
        
        fixture = self.process(wiki)

    def _test_existing_attribute2(self):
        wiki = '''
            |ActionFixture|
            |start|FakeBuyActions|
            |check|total|00.00|
        '''
        
        fixture = self.process(wiki)
        

    def test_foobar(self):
        wiki = '''
           |ActionFixture|
           |start|ChatServer2|
        '''

        fixture = self.process(wiki)

        wiki = '''
           |ActionFixture|
           |enter|user|anna|
           |press|connect|
           |enter|room|lotr|
           |press|new room|
           |press|enter room|
        '''

        fixture = self.process(wiki)
Example #14
0
def runBox(boxUid):

    host = ConsoleHost()

    agnostic.collect()
    #TODO CH remove these test lines
    screen.clear()
    font.draw_generator(generatorFactory(), plotter)
    screen.redraw()

    agnostic.collect()

    boxUid = str(boxUid) # handle case of passing a number

    boxEngine = Engine(box=story.lookupBox(boxUid))
    boxEngine.registerStory(story)
    agnostic.collect()

    while True:
        agnostic.report_collect()
        try:
            tagUid = vault.awaitPresence()
            try:
                cardDict = vault.readJson(tagUid=tagUid)
                if "storyUid" not in cardDict or cardDict["storyUid"] is not loader.storyUid:
                    cardDict = None # existing card data incompatible
            except Exception as e:
                if type(e) is KeyboardInterrupt:
                    raise e
                else:
                    print(e)
                    cardDict = None # couldn't read card for some reason

            if cardDict is not None:
                print("JSON Good")
                card = dictToCard(tagUid, cardDict)
            else:
                print("JSON Bad")
                card = story.createBlankCard(tagUid)

            agnostic.collect()

            boxEngine.handleCard(card, host)
            print("Handled Card")
            vault.writeJson(cardToDict(card), tagUid=tagUid, unselect=True)
            print("Written JSON")
            vault.awaitAbsence()
            print("Card removed")
        except AssertionError as ae:
            print(type(ae).__name__ + str(ae))
        except KeyboardInterrupt:
            break
Example #15
0
class TestRowFixture3(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()
        self.engine.loader = CreateFixture(globals())

    def process(self, wiki):
        self.table = Table(wiki_table_to_plain(wiki))
        return self.engine.process(self.table)

    def test_two_surplus_rows(self):
        wiki = '''
            |OccupantList3|
            |order|
            |1 |
            |2 |
        '''

        fixture = self.process(wiki)

        self.assertEqual(fixture.differ.missing, [])
        self.assertEqual(fixture.differ.surplus, [])
        self.assertEqual(len(self.table.rows), 4)
Example #16
0
 def remove_widget(self, widget):
     widget.removeWidget(True)
     Engine.remove_widget(self, widget)
Example #17
0
 def setUp(self):
     self.engine = Engine()
     self.engine.loader = CreateFixture(globals())
Example #18
0
 def __init__(self, bot, conf):
     Engine.__init__(self, bot, conf)
     self.owners = tuple(x.strip() for x in conf["permission"]["owners"].split(","))
     self.ops = tuple(x.strip() for x in conf["permission"]["ops"].split(","))
Example #19
0
    keyState = KeyboardState(story)

    hosts = dict()
    screens = list()

    hostThreads = list()
    boxUids = list(boxTable.keys())
    boxUids.sort()
    for boxUid in boxUids:
        box = story.lookupBox(boxUid)
        rfid = keyState.create_rfid(boxUid) # TODO can simplify by creating window last, or does RFID need window beforehand?
        screen = st7920Emulator.PillowScreen()
        blackPlotter = screen.create_plotter(True)
        whitePlotter = screen.create_plotter(False)
        engine = Engine(box=box)
        engine.registerStory(story)
        host = Host(
            story = story,
            box = boxTable[boxUid],
            engine=engine,
            screen=screen,
            rfid = rfid,
            smallFont=smallFont,
            bigFont=bigFont,
            blackPlotter=blackPlotter,
            whitePlotter=whitePlotter,
            powerPin = None
        )
        hosts[boxUid] = host
        screens.append(screen)
Example #20
0
    def test_compare(self):

        engine = Engine()
        cell = Cell('1')
        engine.compare(cell, 1)
Example #21
0
 def test_action_fixture(self):
     engine = Engine()
     engine.load_fixture('fit.RowFixture')
     engine.load_fixture('fit.ColumnFixture')
     engine.load_fixture('fit.ActionFixture')
Example #22
0
class TestFixtures(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()
        self.engine.loader = CreateFixture(globals())

    def process(self, wiki):
        return self.engine.process(Table(wiki_table_to_html(wiki)))

    def testSignature(self):
        class FooFixture(object):
            def test_func(self, arg1, arg2):
                self.called = True

        fixture = FooFixture()
        f = getattr(fixture, "test_func")

        self.assert_(inspect.ismethod(f))
        self.assertEqual(2, len(inspect.getargspec(f)[0]) - 1)
        args = [1, 2]
        f(*args)
        self.assert_(fixture.called)

    def test_action_fixture(self):
        wiki = """
            |FakeActionFixture|
            |enter|user  |anna|
            |check|amount|24|
            |check|add   |12|7|
        """

        fixture = self.process(wiki)

        self.assertEqual(fixture.trace[0], ["user", "userName", "anna"])
        self.assertEqual(fixture.trace[1], ["amount", "x", "24"])
        self.assertEqual(fixture.trace[2], ["add", "x", "12", "y", "7"])

    def test_do_fixture(self):
        wiki = """
            |FakeDoFixture|
            |User|anna|Creates|lotr|Room|
        """

        fixture = self.process(wiki)

        self.assertEqual(fixture.trace[0], ["UserCreatesRoom", "userName", "anna", "roomName", "lotr"])

    def test_market_picture(self):

        table = "|TradingStart|"
        name = "TradingStart"
        fixture = globals()[name]()

        fixture.run()
        li = getattr(fixture, "market_picture")
        pic = li["BHP"]

        table = "|PrepareMarket|BHP|"

        def prepare_market(code):
            pass

        prepare_market("BHP")

        table = """
            |market picture|
            |qty  |bid price|ask price|qty  |
            |1,900|     82.0|83.0     |1,900|
            |  500|     82.0|         |     |
        """

        table = Document(wiki_table_to_html(table))

    def test_dual_header(self):
        table = """
            |SubmitOrders|
            |bid  |     |ask  |     |
            |qty  |price|price|qty  |
            |1,900| 82.0|83.0 |1,900|
            |  500| 82.0|     |     |
        """

        table = Table(wiki_table_to_html(table))
        row1 = table.rows[1]
        row2 = table.rows[2]

        l = []
        for prefix, i in rzip(row1, row2):
            l.append(str("%s_%s" % (prefix, i)))

        self.assertEqual(l, ["bid_qty", "bid_price", "ask_price", "ask_qty"])

    def test_function_names(self):
        t = "user creates room"
        prefix = "local"
        words = t.split()
        words.insert(0, prefix)
        f = "_".join(words)
        self.assertEqual(f, "local_user_creates_room")

    def test_if_fails_if_fixture_doesnt_exist(self):
        try:
            fixture = self.process("|NoneExisting|")
        except Exception, inst:
            pass

        self.assertEqual(str(inst), "Could not create fixture 'NoneExisting'")
Example #23
0
class TestColumnFixture(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()
        self.engine.loader = CreateFixture(globals())

    def process(self, wiki):
        self.table = Table(wiki_table_to_plain(wiki))
        return self.engine.process(self.table)

    def test_existing_attribute(self):
        wiki = '''
            |FakeColumnFixture|
            |arg1|arg2|sum()|
            |20|10|35|
        '''

        fixture = self.process(wiki)

        # These are float because this is the type in the fixture
        self.assertEqual(fixture.arg1, 20.0)
        self.assertEqual(fixture.arg2, 10.0)

        # These are string
        self.assertEqual(str(self.table.cell(0,2)), '20')
        self.assertEqual(str(self.table.cell(1,2)), '10')
        self.assertEqual(str(self.table.cell(2,2)), '35')

    def test_failing_test(self):
        wiki = '''
            |FakeColumnFixture|
            |arg1|arg2|sum()|
            |20|10|35|
        '''

        fixture = self.process(wiki)
        cell = self.table.cell(2,2)
        self.assert_(cell.has_failed)
        self.assertEqual(cell.actual, 30.0)

    def test_passing_test(self):
        wiki = '''
            |FakeColumnFixture|
            |arg1|arg2|sum()|
            |20|10|30|
        '''

        fixture = self.process(wiki)
        cell = self.table.cell(2,2)
        self.assert_(cell.has_passed)

    def test_non_existing_attribute(self):
        wiki = '''
            |FakeColumnFixture|
            |quantity|
            |20|
        '''

        try:
            fixture = self.process(wiki)
        except Exception, inst:
            pass
        self.assertEqual(self.table.cell(0,2).error_message,
                         """'FakeColumnFixture' object has no attribute 'quantity'""")
Example #24
0
 def __init__(self):
     self.engine = Engine()
     self.engine.print_traceback = True
     self.proto = FitnesseProtocol(self)
Example #25
0
 def __init__(self, bot, conf):
     Engine.__init__(self, bot, conf)
     self.owners = tuple(x.strip()
                         for x in conf["permission"]["owners"].split(","))
     self.ops = tuple(x.strip()
                      for x in conf["permission"]["ops"].split(","))