Exemplo n.º 1
0
    def test_parse_file_price(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        self.assertEqual(parse_file("test_files\\incorrect_prices.txt",db), 3)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Error in parsing. Make sure in line 4 the price is a valid value\n",capture.getvalue())
Exemplo n.º 2
0
    def test_parse_file_date(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        self.assertEqual(parse_file("test_files\\incorrect_dates.txt", db), 2)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Error in parsing. Make sure in line 2 the time is in ISO-8061 format\n",capture.getvalue())
Exemplo n.º 3
0
    def test_parse_file_units(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        self.assertEqual(parse_file("test_files\\incorrect_units.txt", db), 4)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Error in parsing. Make sure in line 3 the number of "
                         "units is a valid value\n",capture.getvalue())
Exemplo n.º 4
0
    def test_parse_file_filename(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        self.assertEqual(parse_file("test_files\\not_real_file_name.txt",db),1)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Could not open file path \" test_files\\not_real_file_name.txt \". "
                         "Make sure file is in correct directory\n",capture.getvalue())
Exemplo n.º 5
0
    def test_search_db_datetime_not_included(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        val = parse_file("test_files\\sample_test.txt",db)

        # ensures parse_file is working correctly
        self.assertEqual(val, 0)
        self.assertEqual(search_db(datetime.datetime(2017,5,31),db),0)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Price at 2017-05-31 00:00:00+00:00 : 20.15\n",capture.getvalue())
Exemplo n.º 6
0
    def test_get_statistics_empty(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        val = parse_file("test_files\\empty_file.txt", db)

        # ensures parse_file is working correctly
        self.assertEqual(val, 0)

        self.assertEqual(get_statistics(datetime.datetime(2000, 1, 2, 3), datetime.datetime(2020, 1, 2, 3), db), 7)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("File has no entries therefore cannot return information\n",capture.getvalue())
Exemplo n.º 7
0
    def test_search_db_datetime_less(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        val = parse_file("test_files\\sample_test.txt",db)

        # ensures parse_file is working correctly
        self.assertEqual(val, 0)
        self.assertEqual(search_db(datetime.datetime(2005,1,2,3),db),0)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Datetime object given is smaller than the smallest entry found in the file. "
              "Returning information about smallest item\nPrice at 2017-03-01 13:37:59+00:00 : 21.37\n",capture.getvalue())
Exemplo n.º 8
0
    def test_search_db_comparison(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        val = parse_file("test_files\\sample_test.txt",db)

        # ensures parse_file is working correctly
        self.assertEqual(val, 0)
        self.assertEqual(search_db(3,db),6)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Object given is <class 'int'> and cannot be "
                         "compared to a datetime object\n",capture.getvalue())
Exemplo n.º 9
0
    def test_get_statistics_none(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        val = parse_file("test_files\\sample_test.txt", db)

        # ensures parse_file is working correctly
        self.assertEqual(val, 0)

        self.assertEqual(get_statistics(datetime.datetime(2017, 5, 14, 3), datetime.datetime(2017, 5, 18, 3), db), 0)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("No entries in the file within the given dates. Giving information about adjacent dates.\n"
                         "Price at 2017-05-18 03:00:00+00:00 : 21.63\n",capture.getvalue())
Exemplo n.º 10
0
    def test_search_db_datetime_greater(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        val = parse_file("test_files\\sample_test.txt",db)

        # ensures parse_file is working correctly
        self.assertEqual(val, 0)

        self.assertEqual(search_db(datetime.datetime(2020,1,2,3),db),0)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Datetime object given is larger than the largest entry found in the file. "
         "Returning information about largest item\nPrice at 2017-06-12 09:51:21+00:00 : 17.21\n",capture.getvalue())
Exemplo n.º 11
0
    def test_get_statistics_one(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        val = parse_file("test_files\\sample_test.txt",db)

        # ensures parse_file is working correctly
        self.assertEqual(val, 0)

        self.assertEqual(get_statistics(datetime.datetime(2017,5,14,3),datetime.datetime(2017,5,30,3),db),0)

        # reset23.09 21
        sys.stdout = sys.__stdout__

        self.assertEqual("Average Price:  23.09\nMinimum Price:  23.09\n"
                         "Maximum Price:  23.09\nMedian Units:  21.00\n"
                         "Standard Deviation of Units: 0.00\n", capture.getvalue())
Exemplo n.º 12
0
    def test_get_statistics_all(self):
        db = Database()

        # redirect stdout to capture
        capture = StringIO()
        sys.stdout = capture

        val = parse_file("test_files\\sample_test.txt",db)

        # ensures parse_file is working correctly
        self.assertEqual(val, 0)

        self.assertEqual(get_statistics(datetime.datetime(2000,1,2,3),datetime.datetime(2020,1,2,3),db),0)

        # reset
        sys.stdout = sys.__stdout__

        self.assertEqual("Average Price:  20.46\nMinimum Price:  17.21\n"
                         "Maximum Price:  23.09\nMedian Units:  77.50\n"
                         "Standard Deviation of Units: 34615.62\n",capture.getvalue())
Exemplo n.º 13
0
    def test_parse_file(self):
        db = Database()

        self.assertEqual(parse_file("test_files\\sample_test.txt",db), 0)