Exemplo n.º 1
0
class TestDataExtraction(unittest.TestCase):
    def setUp(self):
        # be executed before each test
        self.test_class = PrintClass('classDiagram.txt')

    #def tearDown(self):
    # be executed after each test case
    #print('down')

    def test_get_class_name(self):
        list_1 = ['class a {\n', '    n : String\n', '    add()\n', '}\n']
        list_2 = ['class  {\n', '    n : String\n', '    add()\n', '}\n']
        list_3 = ['    name : String\n', '    add_attributes()\n', '}\n']
        self.assertEqual(self.test_class.get_class_name(list_1), 'a')
        self.assertEqual(self.test_class.get_class_name(list_2), '')
        self.assertIsNone(self.test_class.get_class_name(list_3))

    def test_02(self):
        print(2)
        self.x = 6
        self.assertEqual(6, 3 * 2)

    @unittest.skip('I have not coded how this will work yet.')
    def test_01(self):
        print(1)
        self.assertTrue(None is 42)
        self.x = 666
Exemplo n.º 2
0
 def test_read_txt_file(self):
     print_class = PrintClass()
     actual = print_class.read_txt_file("test2.txt")
     expect = [
         "@startuml\n", "ToyBox *-- Toy\n", "\n", "class ToyBox {\n",
         "    name : String\n", "}\n", "\n", "class Toy {\n", "}\n",
         "@enduml\n"
     ]
     self.assertEqual(expect, actual)
Exemplo n.º 3
0
 def test_get_method_name(self):
     print_class = PrintClass()
     class_item = print_class.class_handler("test_method.docx")
     actual_one = print_class.get_methods(class_item[0])
     expected_one = ["add_toy", "get_toy"]
     actual_two = print_class.get_methods(class_item[1])
     expected_two = ["__str__"]
     self.assertEqual(expected_one, actual_one)
     self.assertEqual(expected_two, actual_two)
 def do_writeCode(self, line):
     """
     Syntax: writeCode
     Creates new files and writes class to each
     :return: None
     """
     PrintClass(self.the_file).outputClasses()
Exemplo n.º 5
0
class Controller:
    file = PrintClass()
    chart = ChartMaker()

    @staticmethod
    def load_file(infile):
        r"""
        >>> Controller.load_file("C:\\Users\Luna\ICT\python\\uml.csv")
        Incorrect file type, please check with help load
        >>> Controller.load_file("test.docx")
        True
        >>> Controller.load_file("test.txt")
        True
        >>> Controller.load_file("C:\\Users\Luna\ICT\\uml.docx")
        File is not found
        """
        try:
            if path.isfile(infile):
                if ".txt" in infile[-4:] or ".docx" in infile[-5:]:
                    Controller.file.class_handler(infile)
                    return True
                else:
                    raise NameError

            else:
                raise FileNotFoundError

        except NameError:
            print("Incorrect file type, please check with help load")
        except FileNotFoundError:
            print("File is not found")
        except Exception as e:
            print(e)

    def save_file(self, file_location):
        try:
            if path.exists(file_location):
                self.file.output_classes(file_location)
            else:
                raise FileNotFoundError
        except FileNotFoundError:
            print("No such directory")
        except Exception as e:
            print(e)

    def create_bar_chart(self):
        all_num = self.file.get_all_num()
        if all_num == [0, 0, 0]:
            return False
        else:
            self.chart.create_bar_chart(all_num)

    def create_pie_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_pie_chart(all_num)

    def create_line_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_line_graph(all_num)
 def setUp(self):
     self.command = Command()
     self.printClass = PrintClass()
     if hasattr(self.printClass, 'fileInput'):
         self.printClass.fileProcessor.relationship_list = [
             'Zoo "1" o-- "many" Animal', '"1" *-- "many"', '*--'
         ]
     self.printClass.class_list = [[
         'class Zoo {\n', '    name : String\n', '    location : String\n',
         '    add_animal()\n', '    get_animal()\n', '}\n'
     ],
                                   [
                                       'class Animal {\n',
                                       '    name : String\n',
                                       '    number : Integer\n',
                                       '    __str__()\n', '}\n'
                                   ]]
     self.controller = Controller()
     self.command = Command()
Exemplo n.º 7
0
class Controller:
    file = PrintClass()
    chart = ChartMaker()

    @staticmethod
    def load_file(infile):
        r"""
        >>> Controller.load_file("test_read_file.csv")
        Incorrect file type, please see help load
        >>> Controller.load_file("test.docx")
        The PlantUML file is loaded
        [['class ToyBox {\n', '}\n'], ['class Toy {\n', '}\n']]
        >>> Controller.load_file("test.txt")
        The PlantUML file is loaded
        [['class ToyBox {\n', '}\n'], ['class Toy {\n', '}\n']]
        >>> Controller.load_file("C:\\Users\Luna\ICT\\test2.docx")
        File is not found
        """
        try:
            if ".txt" in infile[-4:] or ".docx" in infile[-5:]:
                Controller.file.class_handler(infile)
                content = Controller.file.class_list
                print("The PlantUML file is loaded")
                return content

            else:
                message = "Incorrect file type, please see help load"
                raise NameError(message)

        except NameError as e:
            print(e)
        except FileNotFoundError:
            print("File is not found")
        except Exception as e:
            print(e)

    def save_file(self, file_location):
        self.file.output_classes(file_location)

    def create_bar_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_bar_chart(all_num)

    def create_pie_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_pie_chart(all_num)

    def create_line_chart(self):
        all_num = self.file.get_all_num()
        self.chart.create_line_graph(all_num)
Exemplo n.º 8
0
 def setUp(self):
     # be executed before each test
     self.test_class = PrintClass()
     self.validator = Validator()
     self.controller = Controller()
Exemplo n.º 9
0
class TestDataExtraction(unittest.TestCase):
    # Clement
    def setUp(self):
        # be executed before each test
        self.test_class = PrintClass()
        self.validator = Validator()
        self.controller = Controller()

    def test_get_class_name(self):
        list_1 = ['class a {\n', '    n : String\n', '    add()\n', '}\n']
        list_2 = ['class  {\n', '    n : String\n', '    add()\n', '}\n']
        list_3 = ['    name : String\n', '    add_attributes()\n', '}\n']
        self.assertEqual(self.test_class.get_class_name(list_1), 'a')
        self.assertEqual(self.test_class.get_class_name(list_2), '')
        self.assertIsNone(self.test_class.get_class_name(list_3))

    def test_validate_attribute_name_true(self):
        self.assertTrue(self.validator.validate_attribute_name("attribute"))
        self.assertTrue(self.validator.validate_attribute_name("clement"))

    def test_validate_attribute_name_false(self):
        self.assertFalse(self.validator.validate_attribute_name("<clement"))
        self.assertFalse(self.validator.validate_attribute_name("??i"))
        self.assertFalse(self.validator.validate_attribute_name("break"))
        self.assertFalse(self.validator.validate_attribute_name("pass"))
        self.assertFalse(self.validator.validate_attribute_name(42))
        self.assertFalse(self.validator.validate_attribute_name(3.14))
        self.assertFalse(
            self.validator.validate_attribute_name(
                '--------------------------------------'
                '-------------------------------------'))

    # Luna
    def test_validate_class_name_is_true(self):
        result_1 = self.validator.validate_class_name("Name")
        result_2 = self.validator.validate_class_name("ClassName")
        self.assertTrue(result_1, "invalid class name")
        self.assertTrue(result_2, "invalid class name")

    def test_validate_class_name_using_special_char(self):
        result = self.validator.validate_class_name("Name$%^&")
        self.assertFalse(result, "valid class name")

    def test_validate_class_name_using_lower(self):
        result = self.validator.validate_class_name("name")
        self.assertFalse(result, "valid class name")

    def test_validate_class_name_start_with_num(self):
        result = self.validator.validate_class_name("123Name")
        self.assertFalse(result, "valid class name")

    def test_validate_class_name_start_with_char(self):
        result = self.validator.validate_class_name("$%^_+Name")
        self.assertFalse(result, "valid class name")

    def test_read_word_file(self):
        actual = self.test_class.read_word_file("test2.docx")
        expect = [
            "@startuml\n", "ToyBox *-- Toy\n", "\n", "class ToyBox {\n",
            "    name : String\n", "}\n", "\n", "class Toy {\n", "}\n",
            "@enduml\n"
        ]
        self.assertEqual(expect, actual, "cannot read word file")

    def test_read_txt_file(self):
        actual = self.test_class.read_txt_file("test2.txt")
        expect = [
            "@startuml\n", "ToyBox *-- Toy\n", "\n", "class ToyBox {\n",
            "    name : String\n", "}\n", "\n", "class Toy {\n", "}\n",
            "@enduml\n"
        ]
        self.assertEqual(expect, actual, "cannot read txt file")

    def test_load_word_file(self):
        actual = self.controller.load_file("test2.docx")
        self.assertTrue(actual, "cannot load word file")

    def test_load_txt_file(self):
        actual = self.controller.load_file("test2.txt")
        self.assertTrue(actual, "cannot load txt file")

    def test_load_file_not_found_exception(self):
        actual = self.controller.load_file("C:\\Users\\Luna\\ICT\\test2.txt")
        self.assertRaises(FileNotFoundError, actual)

    def test_load_incorrect_file_exception(self):
        actual = self.controller.load_file("test2.csv")
        self.assertRaises(NameError, actual)

    def test_get_method_name(self):
        class_item = self.test_class.class_handler("test_method.docx")
        actual_one = self.test_class.get_methods(class_item[0])
        expected_one = ["add_toy", "get_toy"]
        actual_two = self.test_class.get_methods(class_item[1])
        expected_two = ["__str__"]
        self.assertEqual(expected_one, actual_one, "cannot get method name")
        self.assertEqual(expected_two, actual_two, "cannot get method name")

    # Rajan
    def test_validate_method_name_is_false(self):
        validator = Validator()
        result_1 = validator.validate_method_name("Get")
        result_2 = validator.validate_method_name("1_get")
        result_3 = validator.validate_method_name("get_Name")
        self.assertFalse(result_1)
        self.assertFalse(result_2)
        self.assertFalse(result_3)

    def test_validate_method_name_is_true2(self):
        validator = Validator()
        result_1 = validator.validate_method_name("_get")
        result_2 = validator.validate_method_name("get1")
        self.assertTrue(result_1)
        self.assertTrue(result_2)

    def test_validate_method_name_is_true(self):
        validator = Validator()
        result_1 = validator.validate_method_name("method_name")
        result_2 = validator.validate_method_name("get")
        self.assertTrue(result_1)
        self.assertTrue(result_2)

    def test_validate_method_name_is_false2(self):
        validator = Validator()
        result_1 = validator.validate_method_name("Name")
        result_2 = validator.validate_method_name("get_Name")
        result_3 = validator.validate_method_name("1_get")
        self.assertFalse(result_1)
        self.assertFalse(result_2)
        self.assertFalse(result_3)
Exemplo n.º 10
0
 def setUp(self):
     # be executed before each test
     self.test_class = PrintClass('classDiagram.txt')
class TestBadSmells(unittest.TestCase):
    def setUp(self):
        self.command = Command()
        self.printClass = PrintClass()
        if hasattr(self.printClass, 'fileInput'):
            self.printClass.fileProcessor.relationship_list = [
                'Zoo "1" o-- "many" Animal', '"1" *-- "many"', '*--'
            ]
        self.printClass.class_list = [[
            'class Zoo {\n', '    name : String\n', '    location : String\n',
            '    add_animal()\n', '    get_animal()\n', '}\n'
        ],
                                      [
                                          'class Animal {\n',
                                          '    name : String\n',
                                          '    number : Integer\n',
                                          '    __str__()\n', '}\n'
                                      ]]
        self.controller = Controller()
        self.command = Command()

    def test_do_display(self):
        self.command.do_display("/a")
        self.command.do_display("/l")
        self.command.do_display("/p")
        self.command.do_display("/o")
        self.command.do_display("")

    def test_get_class_name(self):
        self.assertEqual(
            self.printClass.get_class_name(
                ['class z {\n', '    n : String\n', '    add()\n', '}\n']),
            'z')
        self.printClass.get_class_name(
            [' z {\n', '    n : String\n', '    add()\n', '}\n'])

    def test_output_classes(self):
        self.printClass.output_classes("")

    def test_output_class_exception_invalid_attribute_name(self):
        try:
            self.printClass.output_class([
                'class zoo {\n', '    Name : String\n',
                '    location : String\n', '    add_animal()\n',
                '    get_animal()\n', '}\n'
            ])
        except NameError:
            self.fail("output_class raised NameError unexpectedly")

    def test_output_class_exception_invalid_method_name(self):
        self.assertEqual(
            self.printClass.output_class([
                'class Zoo {\n', '    name : String\n',
                '    location : String\n', '    Add_animal()\n',
                '    Get_animal()\n', '}\n'
            ]), 'class Zoo:\n'
            '    def __init__(self, name, location):\n'
            '        self.name = name\n'
            '        self.location = location\n'
            '# method name is invalid\n'
            '# method name is invalid\n')

    def test_output_class_test_no_attribute(self):
        self.printClass.output_class([
            'This is a first line', 'Zoo "1" o - - "many" Animal',
            'class Zoo {\n', '    Add_animal()\n', '    Get_animal()\n', '}\n'
        ])

    def test_output_class_test_relationships(self):
        self.printClass.class_handler("uml.txt")

    def test_get_all_num(self):
        self.printClass.get_all_num()

    def test_read_text_file(self):
        self.printClass.read_txt_file("clement.txt")

    def test_identify_r_type(self):
        self.printClass.identify_r_type("o-- <-- <..", "name")
        self.printClass.identify_r_type("<-- <-- <--", "name")
        self.printClass.identify_r_type("o-- o-- o--", "name")
        self.printClass.identify_r_type("<.. <.. <..", "name")
        self.printClass.identify_r_type("<.. <..", "name")
        self.printClass.identify_r_type('"_ #~~ _"', "name")
        self.printClass.identify_r_type('"1" o-- "many"', "name")
        self.printClass.identify_r_type('"1" *-- "many" "1" *-- "many"',
                                        "name")
        self.printClass.identify_r_type("o-- *-- <..", "name")

    def test_class_handler(self):
        self.printClass.class_handler("test3.csv")
        self.printClass.class_handler("test4.txt")

    def test_fileHandler(self):
        self.controller.load_file("uml.txt")
        self.controller.save_file("")
        self.controller.load_file("test.docx")
        self.controller.save_file("")
        self.controller.load_file("test1.docx")
        self.controller.save_file("")
        self.controller.load_file("test2.docx")
        self.controller.save_file("")
        self.controller.load_file("test3.txt")
        self.controller.save_file("")
        self.controller.load_file("test4.txt")
        self.controller.save_file("")
Exemplo n.º 12
0
 def setUp(self):
     self.test_class = PrintClass()
     self.validator = Validator()
Exemplo n.º 13
0
class TestDataExtraction(unittest.TestCase):
    # Clement
    def setUp(self):
        self.test_class = PrintClass()
        self.validator = Validator()

    def test_get_class_name_normal(self):
        list_1 = ['class a {\n', '    n : String\n', '    add()\n', '}\n']
        self.assertEqual(self.test_class.get_class_name(list_1), 'a')

    def test_get_class_name_none(self):
        list_2 = ['class  {\n', '    n : String\n', '    add()\n', '}\n']
        self.assertEqual(self.test_class.get_class_name(list_2), '')

    def test_get_class_name_gone(self):
        list_3 = ['    name : String\n', '    add_attributes()\n', '}\n']
        self.assertIsNone(self.test_class.get_class_name(list_3))

    def test_validate_attribute_name_true_attribute(self):
        self.assertTrue(self.validator.validate_attribute_name("attribute"))

    def test_validate_attribute_name_true_clement(self):
        self.assertTrue(self.validator.validate_attribute_name("clement"))

    def test_validate_attribute_name_false_mixed(self):
        self.assertFalse(self.validator.validate_attribute_name("<clement"))

    def test_validate_attribute_name_false_mixed2(self):
        self.assertFalse(self.validator.validate_attribute_name("??i"))

    def test_validate_attribute_name_false_special(self):
        self.assertFalse(self.validator.validate_attribute_name("break"))

    def test_validate_attribute_name_false_special2(self):
        self.assertFalse(self.validator.validate_attribute_name("pass"))

    def test_validate_attribute_name_false_number(self):
        self.assertFalse(self.validator.validate_attribute_name(42))

    def test_validate_attribute_name_false_float(self):
        self.assertFalse(self.validator.validate_attribute_name(3.14))

    def test_validate_attribute_name_false_long(self):
        self.assertFalse(
            self.validator.validate_attribute_name(
                '--------------------------------------'
                '-------------------------------------'))

    # Luna
    def test_validate_class_name_is_true(self):
        validator = Validator()
        result_1 = validator.validate_class_name("Name")
        result_2 = validator.validate_class_name("ClassName")
        self.assertTrue(result_1)
        self.assertTrue(result_2)

    def test_validate_class_name_using_special_char(self):
        validator = Validator()
        result = validator.validate_class_name("Name$%^&")
        self.assertFalse(result)

    def test_validate_class_name_using_lower(self):
        validator = Validator()
        result = validator.validate_class_name("name")
        self.assertFalse(result)

    def test_validate_class_name_start_with_num(self):
        validator = Validator()
        result = validator.validate_class_name("123Name")
        self.assertFalse(result)

    def test_read_word_file(self):
        print_class = PrintClass()
        actual = print_class.read_word_file("test2.docx")
        expect = [
            "@startuml\n", "ToyBox *-- Toy\n", "\n", "class ToyBox {\n",
            "    name : String\n", "}\n", "\n", "class Toy {\n", "}\n",
            "@enduml\n"
        ]
        self.assertEqual(expect, actual)

    def test_read_txt_file(self):
        print_class = PrintClass()
        actual = print_class.read_txt_file("test2.txt")
        expect = [
            "@startuml\n", "ToyBox *-- Toy\n", "\n", "class ToyBox {\n",
            "    name : String\n", "}\n", "\n", "class Toy {\n", "}\n",
            "@enduml\n"
        ]
        self.assertEqual(expect, actual)

    def test_load_word_file(self):
        controller = Controller()
        actual = controller.load_file("test2.docx")
        expected = [['class ToyBox {\n', '    name : String\n', '}\n'],
                    ['class Toy {\n', '}\n']]
        self.assertEqual(expected, actual)

    def test_load_txt_file(self):
        controller = Controller()
        actual = controller.load_file("test2.txt")
        expected = [['class ToyBox {\n', '    name : String\n', '}\n'],
                    ['class Toy {\n', '}\n']]
        self.assertEqual(expected, actual)

    def test_load_file_not_found_exception(self):
        controller = Controller()
        actual = controller.load_file("C:\\Users\\Luna\\ICT\\test2.txt")
        self.assertRaises(FileNotFoundError, actual)

    def test_load_incorrect_file_exception(self):
        controller = Controller()
        actual = controller.load_file("test2.csv")
        self.assertRaises(NameError, actual)

    def test_get_method_name(self):
        print_class = PrintClass()
        class_item = print_class.class_handler("test_method.docx")
        actual_one = print_class.get_methods(class_item[0])
        expected_one = ["add_toy", "get_toy"]
        actual_two = print_class.get_methods(class_item[1])
        expected_two = ["__str__"]
        self.assertEqual(expected_one, actual_one)
        self.assertEqual(expected_two, actual_two)

    # Rajan
    def test_validate_method_name_is_false(self):
        validator = Validator()
        result_1 = validator.validate_method_name("Get")
        result_2 = validator.validate_method_name("1_get")
        result_3 = validator.validate_method_name("get_Name")
        self.assertFalse(result_1)
        self.assertFalse(result_2)
        self.assertFalse(result_3)

    def test_validate_method_name_is_true(self):
        validator = Validator()
        result_1 = validator.validate_method_name("method_name")
        result_2 = validator.validate_method_name("get")
        self.assertTrue(result_1)
        self.assertTrue(result_2)

    def test_validate_method_name_using_special_char(self):
        validator = Validator()
        result = validator.validate_method_name("Name$%^&")
        self.assertFalse(result)

    def test_read_txt_file3(self):
        print_class = PrintClass()
        actual = print_class.read_txt_file("test3.txt")
        expect = [
            "@startuml\n", "ToyBox *-- Toy\n", "\n", "class ToyBox {\n",
            "    name : String\n", "}\n", "\n", "class Toy {\n",
            "    number: int\n", "}\n", "@enduml\n"
        ]
        self.assertEqual(expect, actual)

    def test_load_txt_file3(self):
        controller = Controller()
        actual = controller.load_file("test3.txt")
        expected = [['class ToyBox {\n', '    name : String\n', '}\n'],
                    ['class Toy {\n', '    number: int\n', '}\n']]
        self.assertEqual(expected, actual)

    def test_validate_method_name_is_true2(self):
        validator = Validator()
        result_1 = validator.validate_method_name("_get")
        result_2 = validator.validate_method_name("get1")
        self.assertTrue(result_1)
        self.assertTrue(result_2)

    def test_validate_method_name_start_with_num(self):
        validator = Validator()
        result = validator.validate_class_name("123")
        self.assertFalse(result)

    def test_validate_method_name_start_with_capital(self):
        validator = Validator()
        result = validator.validate_method_name("N")
        self.assertFalse(result)

    def test_load_incorrect_file_format(self):
        controller = Controller()
        actual = controller.load_file("test.pdf")
        self.assertRaises(NameError, actual)