Beispiel #1
0
 def test_calls_argparse_function_argument_parser(self,
                                                  mock_argument_parser):
     """ Unit test for ArgumentParser, checks that our argument parser was created correctly """
     ticker_argument_parser()
     mock_argument_parser.assert_called_with(
         description="Select a file or feed to parse.",
         fromfile_prefix_chars='@')
Beispiel #2
0
    def test_calls_argparse_function_argument_parser(self, mock_parser):
        """
        Unit test for controller.utilities.ticker_argument_parser.

        Checks that our argument parser was reated correctly.
        """

        self.description = "Select a file or feed to parse."
        ticker_argument_parser()
        mock_parser.assert_called_with(description=self.description,
                                       fromfile_prefix_chars='@')
Beispiel #3
0
    def test_default_timer(self):
        """ Unit test for controller.utilities.ticker_argument_parser's default timer value. """

        sys.argv = ['this is the prog field (the name of the program']
        args = ticker_argument_parser()

        self.assertTrue(args.timer, args.logger)
        self.assertFalse(args.file)
        self.assertEqual(args.timer, 10)
Beispiel #4
0
    def test_timer(self):
        """ Unit test for controller.utilities.ticker_argument_parser's timer argument. """

        sys.argv = ['news ticker', '--timer', '17']
        args = ticker_argument_parser()

        self.assertTrue(args.timer, args.logger)
        self.assertFalse(args.file)
        self.assertEqual(args.timer, 17)
Beispiel #5
0
    def test_file(self):
        """ Unit test for controller.utilities.ticker_argument_parser's file argument. """

        fake_file = ['fakefile.txt']
        sys.argv = ['test', '--file', fake_file[0]]
        args = ticker_argument_parser()

        self.assertTrue(args.file, args.timer)
        self.assertEqual(args.file, fake_file)
Beispiel #6
0
    def test_url(self):
        """ Unit test for controller.utilities.ticker_argument_parser's url argument. """

        fake_url = ['www.fakeurl.com']
        sys.argv = ['test', '--url', fake_url[0]]
        args = ticker_argument_parser()

        self.assertTrue(args.url, args.timer)
        self.assertEqual(args.url, fake_url)
Beispiel #7
0
    def test_has_each_argument(self):
        """ Unit test for controller.utilities.ticker_argument_parser. Are all args present? """

        sys.argv = ['PRSST']
        args = ticker_argument_parser()
        self.assertTrue('url' in args)
        self.assertTrue('file' in args)
        self.assertTrue('logger' in args)
        self.assertTrue('timer' in args)
Beispiel #8
0
    def test_logger(self):
        """ Unit test for controller.utilities.ticker_argument_parser's logger argument. """

        fake_logger = ['WARNING']
        sys.argv = ['test', '--logger', fake_logger[0]]
        args = ticker_argument_parser()

        self.assertTrue(args.logger, args.timer)
        self.assertFalse(args.file)
        self.assertEqual(args.logger, fake_logger)
Beispiel #9
0
    def test_all_args(self):
        """ Unit test for controller.utilities.ticker_argument_parser testing the handling of all arguments at once."""

        # TODO, finish this test. The argument needs to be expanded

        url = "www.notasite.com"
        time = 13
        file = 'some/file.txt'
        logger = 'ERROR'
        sys.argv = ['test', '--url', url]
        args = ticker_argument_parser()
        self.assertEqual(args.url[0], url)
Beispiel #10
0
    def test_multiple_urls(self):
        """
        Unit test for controller.utilities.ticker_argument_parser's url argument with multiple urls.
        """

        fake_url = ['www.fakeurl.com', 'www.otherurl.com']
        sys.argv = ['test', '--url', fake_url[0], fake_url[1]]
        args = ticker_argument_parser()

        self.assertTrue(args.url, args.timer)
        self.assertEqual(args.url[0], fake_url[0])
        self.assertEqual(args.url[1], fake_url[1])
Beispiel #11
0
def main(mainView):
    """ Controller.tiny_ticker.main gathers command-line args, calls the model, initiates the title loop

    Arguments:
        mainView: an instance of model.MainView
    """

    tt_logger.debug('main')

    arguments = ticker_argument_parser()
    feed = parse(arguments.url[0])
    feed.reverse()
    ten_second_loop(mainView, arguments.timer, feed)
Beispiel #12
0
Contains methods for mediating communication between this application's modules. It also initializes
and runs the Tiny Ticker application.
"""

import threading
from model import parser
from typing import List
from model.article import Article
from view.main_view import start_main_view, MainView
from model.feed_manager import create_feed_manager, FeedManager
from controller.utilities import logger, ticker_argument_parser

tt_logger = logger('controller.tiny_ticker')

arguments = ticker_argument_parser()


def ten_second_loop(main_view: MainView, cycle, feed_manager: FeedManager):
    """
    controller.tiny_ticker.ten_second_loop

    Switches the display every <cycle> seconds. This function spans a timed looping thread. Every 'cycle' seconds this
    function calls it's self to continue the loop. It is a daemon thread so it acts in the background and it calls
    controller.title_loop.call_switch_display.

    Arguments:
        main_view -- the MainView which displays articles.
        cycle -- the amount of time between view changes. User input from the command line.
        feed_manager -- the FeedManager which will provide the next article to display
    """