Esempio n. 1
0
    def test_non_int_raises_value_error(self):
        io = IO()
        reader = io.read(self.invalid_file)

        with self.assertRaises(ValueError):
            for number in reader:
                pass
Esempio n. 2
0
    def test_reads_correct_ints(self):
        """Tests to ensure the correct numbers are returned

        Implicitly bound to the values in valid_file.txt. Make sure to keep the
        values in sync or use a different file if diverging often.
        """
        io = IO()
        reader = io.read(self.valid_file)

        self.assertItemsEqual([5, 6, 2, 4, 7, 232, 3], reader)
Esempio n. 3
0
def run(args):
    """Runs the core of the script; reading the file and counting the top n
    ints

    Split out as a separate function to facilitate optional profiling

    :param args: the arguments object generated by the script call
    """
    io = IO()
    reader = io.read(args.path)

    top = TopN(args.n)

    for number in reader:
        top.push(number)

    top_n = top.get_top_n()

    print("\n".join(map(str, top_n)))
Esempio n. 4
0
    def test_values_integers(self):
        io = IO()
        reader = io.read(self.valid_file)

        for number in reader:
            self.assertIsInstance(number, int)
Esempio n. 5
0
 def test_throws_if_path_non_readable(self):
     io = IO()
     with self.assertRaises(IOError):
         reader = io.read("path/that/doesn't/exist")
         for number in reader:
             pass