Exemplo n.º 1
0
    def test_custom_session(self):
        """
        Test that, when defining a custom session, the timelines are created
        correctly.
        """
        timeline_list = TimelineList()

        visible_string = 'home, mentions, search:turses'
        self.session.append_visible_timelines(visible_string, timeline_list)

        # check that the visible timelines are appended correctly
        self.assertTrue(len(timeline_list), 3)

        self.assertTrue(is_home_timeline(timeline_list[0]))
        self.assertTrue(is_mentions_timeline(timeline_list[1]))
        self.assertTrue(is_search_timeline(timeline_list[2]))

        self.assertEqual(
            timeline_list.visible_timelines,
            [timeline_list[0], timeline_list[1], timeline_list[2]])

        # now let's append the buffers in the background
        buffers_string = 'messages'
        self.session.append_background_timelines(buffers_string, timeline_list)

        self.assertTrue(len(timeline_list), 4)

        self.assertTrue(is_messages_timeline(timeline_list[3]))
Exemplo n.º 2
0
Arquivo: cli.py Projeto: louipc/turses
def main():
    """
    Launch ``turses``.
    """
    set_title(__name__)
    set_encoding('utf8')

    args = read_arguments()

    # check if stdout has to be restored after program exit
    if any([
            args.debug, args.offline,
            getattr(args, 'help', False),
            getattr(args, 'version', False)
    ]):
        # we are going to print information to stdout
        save_and_restore_stdout = False
    else:
        save_and_restore_stdout = True

    if save_and_restore_stdout:
        save_stdout()

    # parse arguments and load configuration
    configuration.parse_args(args)
    configuration.load()

    # start logger
    logging.basicConfig(filename=LOG_FILE, level=configuration.logging_level)

    # create view
    curses_interface = CursesInterface()

    # create model
    timeline_list = TimelineList()

    # create API
    api = create_async_api(MockApi if args.offline else TweepyApi)

    # create controller
    turses = Turses(
        ui=curses_interface,
        api=api,
        timelines=timeline_list,
    )

    try:
        turses.start()
    except Exception:
        # A unexpected exception occurred, open the debugger in debug mode
        if args.debug or args.offline:
            import pdb
            pdb.post_mortem()
    finally:
        if save_and_restore_stdout:
            restore_stdout()

        restore_title()

        exit(0)
Exemplo n.º 3
0
    def __init__(self, ui, api_backend):
        self.ui = ui
        self.editor = None

        # Model
        self.timelines = TimelineList()
        self.timelines.subscribe(self)

        # Mode
        self.mode = self.INFO_MODE

        # API
        oauth_token = configuration.oauth_token
        oauth_token_secret = configuration.oauth_token_secret
        self.api = AsyncApi(
            api_backend,
            access_token_key=oauth_token,
            access_token_secret=oauth_token_secret,
        )
Exemplo n.º 4
0
 def setUp(self):
     self.timeline_list = TimelineList()
Exemplo n.º 5
0
 def setUp(self):
     self.timelines = TimelineList()
     self.controller = Controller(ui=Mock(),
                                  api=MockApi('foo', 'bar'),
                                  timelines=self.timelines)