<commit_before>#!/usr/bin/env python3


from configparser import ConfigParser
from io import StringIO
import os

import unittest
from unittest.mock import patch

from cheat.printer import *


class PrinterTest(unittest.TestCase):
    """Some basic tests to check the Printer classes"""

    def setUp(self):
        """
        Setting up the test by reading the test cheatsheet with expected content to test against.
        """

        directory = os.path.dirname(os.path.realpath(__file__))
        testfile = os.path.join(directory, "test.ini")
        self.cp = ConfigParser()
        self.cp.read(testfile)

    def test_PrinterFactory_InlinePrinter(self):
        """
        See if the PrinterFactory is giving us the objects we want.
        """

        self.assertIs(
            PrinterFactory.create_printer("InlinePrinter"),
            InlinePrinter
        )

    def test_PrinterFactory_BreaklinePrinter(self):
        """
        See if the PrinterFactory is giving us the objects we want.
        """

        self.assertIs(
            PrinterFactory.create_printer("BreaklinePrinter"),
            BreaklinePrinter
        )

    def test_PrinterFactory_NonsensePrinter(self):
        """
        See if PrinterFactory
        """

        # Using lambda turns our dictionary lookup into a callable.
        self.assertRaises(KeyError, lambda: PrinterFactory.create_printer("NonsensePrinter"))

    def test_InlinePrinter(self):
        """
        Testing if the InlinePrinter does its job.
        """

        #TODO Make this more readable
        expected_output = "test cheat a lorem\ntest cheat b ipsum\ntest cheat c dolor\n"
        printer = InlinePrinter(self.cp)

        with patch('sys.stdout', new=StringIO()) as fake_out:
            printer.printsheet()
            self.assertEqual(fake_out.getvalue(), expected_output)

    def test_InlinePrinter_width(self):
        """
        Test to see if the calculated width is correct.
        """

        printer = InlinePrinter(self.cp)

        expected_length = str(len('Test Cheat A'))
        self.assertEqual(printer.width, expected_length)

    def test_BreaklinePrinter(self):
        """
        Testing if the BreaklinePrinter does its job
        """

        #TODO Make this more readable
        expected_output = "test cheat a \n lorem\ntest cheat b \n ipsum\ntest cheat c \n dolor\n"
        printer = BreaklinePrinter(self.cp)

        with patch('sys.stdout', new=StringIO()) as fake_out:
            printer.printsheet()
            self.assertEqual(fake_out.getvalue(), expected_output)


    def test_Printer_printsheet(self):
        """
        Testing if the printsheet for loop does its job
        """

        #TODO Make this more readable
        expected_output = "test cheat a\ntest cheat b\ntest cheat c\n"
        printer = Printer(self.cp)
        template = "{0}"

        with patch('sys.stdout', new=StringIO()) as fake_out:
            printer.printsheet(template)
            self.assertEqual(fake_out.getvalue(), expected_output)


if __name__ == '__main__':
    unittest.main()<commit_msg>Cleaned up import. No more * :snake:<commit_after>#!/usr/bin/env python3


from configparser import ConfigParser
from io import StringIO
import os

import unittest
from unittest.mock import patch

#from cheat.printer import *
import cheat.printer as cp

class PrinterTest(unittest.TestCase):
    """Some basic tests to check the Printer classes"""

    def setUp(self):
        """
        Setting up the test by reading the test cheatsheet with expected content to test against.
        """

        directory = os.path.dirname(os.path.realpath(__file__))
        testfile = os.path.join(directory, "test.ini")
        self.cp = ConfigParser()
        self.cp.read(testfile)

    def test_PrinterFactory_InlinePrinter(self):
        """
        See if the PrinterFactory is giving us the objects we want.
        """

        self.assertIs(
            cp.PrinterFactory.create_printer("InlinePrinter"),
            cp.InlinePrinter
        )

    def test_PrinterFactory_BreaklinePrinter(self):
        """
        See if the PrinterFactory is giving us the objects we want.
        """

        self.assertIs(
            cp.PrinterFactory.create_printer("BreaklinePrinter"),
            cp.BreaklinePrinter
        )

    def test_PrinterFactory_NonsensePrinter(self):
        """
        See if PrinterFactory
        """

        # Using lambda turns our dictionary lookup into a callable.
        self.assertRaises(KeyError, lambda: cp.PrinterFactory.create_printer("NonsensePrinter"))

    def test_InlinePrinter(self):
        """
        Testing if the InlinePrinter does its job.
        """

        #TODO Make this more readable
        expected_output = "test cheat a lorem\ntest cheat b ipsum\ntest cheat c dolor\n"
        printer = cp.InlinePrinter(self.cp)

        with patch('sys.stdout', new=StringIO()) as fake_out:
            printer.printsheet()
            self.assertEqual(fake_out.getvalue(), expected_output)

    def test_InlinePrinter_width(self):
        """
        Test to see if the calculated width is correct.
        """

        printer = cp.InlinePrinter(self.cp)

        expected_length = str(len('Test Cheat A'))
        self.assertEqual(printer.width, expected_length)

    def test_BreaklinePrinter(self):
        """
        Testing if the BreaklinePrinter does its job
        """

        #TODO Make this more readable
        expected_output = "test cheat a \n lorem\ntest cheat b \n ipsum\ntest cheat c \n dolor\n"
        printer = cp.BreaklinePrinter(self.cp)

        with patch('sys.stdout', new=StringIO()) as fake_out:
            printer.printsheet()
            self.assertEqual(fake_out.getvalue(), expected_output)


    def test_Printer_printsheet(self):
        """
        Testing if the printsheet for loop does its job
        """

        #TODO Make this more readable
        expected_output = "test cheat a\ntest cheat b\ntest cheat c\n"
        printer = cp.Printer(self.cp)
        template = "{0}"

        with patch('sys.stdout', new=StringIO()) as fake_out:
            printer.printsheet(template)
            self.assertEqual(fake_out.getvalue(), expected_output)


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.0909668201301794, 'fraction_numerical': 0.0006350214319733291, 'mean_word_length': 2.3962264150943398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1165753', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1768, 'n_words': 482}