コード例 #1
0
 def __init__(self):
     super().__init__()
     self.intro = "\nwelcome to this cmd. type help_all for a list of " \
                  "commands,\nor for a specific command type 'help'" \
                  "followed by the command.\n" \
                  "Some commands require others to be completed first. If "\
                  "lost, use the help menu."
     self.prompt = "==>  "
     self.name = ""
     self.file_type = ""
     self.output_file_dir = ""
     self.selected_output_dir = False
     self.selected_file_type = False
     self.file_reader = FileReader()
     self.dir_reader = DirectoryReader()
     self.js_reader = JsParser()
コード例 #2
0
    def load_words(self, file_names):
        self.__words = FileReader().read(file_names[0])

        label = Label(text="\n".join(self.__words))
        self.body_widget.add_widget(label)

        self.dismiss_popup()

        self.__solver = Solver()
コード例 #3
0
def console_mode_solve():
    file_reader = FileReader()
    geometry_present = file_reader.read(args.geometry)

    height = len(geometry_present)
    if height < 1:
        print("Incorrect geometry format. Try main.py -h or --help",
              file=sys.stderr)
        exit(1)

    width = len(geometry_present[0])

    geometry = GeometryParser().parse(geometry_present)
    words = file_reader.read(args.words)
    solution = Solver().solve(geometry, words, args.reversed)
    present = Presenter().get_present(width,
                                      height,
                                      solution,
                                      filled_grid=False)
    for line in present:
        print("".join(line))
コード例 #4
0
    def load_geometry(self, file_names):
        self.body_widget.clear_widgets()

        self.__geometry_present = FileReader().read(file_names[0])
        self.__geometry_graph = GeometryParser().parse(self.__geometry_present)

        self.__geometry_widget = GeometryWidget()
        self.__geometry_widget.show_geometry(self.__geometry_present)
        self.body_widget.add_widget(self.__geometry_widget)

        self.dismiss_popup()

        self.__solver = Solver()
コード例 #5
0
class TestFileReader(TestCase):
    def setUp(self):
        self.file_reader = FileReader()
        self.current_dir = getcwd()

    def test_read_txt_file(self):
        """This test simply tests the basic reader - whether it can correctly
         read a regular .txt file"""
        file_dir = str.format("{}/testing_files/not_a_js_file.txt",
                              self.current_dir).replace("\\", "/")
        file_contents = "This is not a JS file!"
        self.assertEqual(self.file_reader.get_file_contents(file_dir),
                         file_contents)

    def test_read_js_file(self):
        """This tests to ensure it can correctly read a .js file contents"""
        file_dir = str.format("{}/testing_files/test_file_4.js",
                              self.current_dir).replace("\\", "/")
        file_contents = 'class TestClass {\n' \
                        '    constructor() {\n' \
                        '    this.attribute1 = "";\n' \
                        '    this.attribute2 = "";\n' \
                        '    }\n' \
                        '}'
        self.assertEqual(self.file_reader.get_file_contents(file_dir),
                         file_contents)

    def test_reject_wrong_file(self):
        """This tests to ensure the class will reject a file that's not
        a js file, when using that particular checker."""
        file_dir = str.format("{}/testing_files/not_a_js_file.txt",
                              self.current_dir).replace("\\", "/")
        self.assertFalse(self.file_reader.is_valid_file(file_dir))

    def test_accept_right_file(self):
        """This tests to ensure the class will accept a file that's
                a js file, when using that particular checker."""
        file_dir = str.format("{}/testing_files/test_file_1.js",
                              self.current_dir).replace("\\", "/")
        self.assertTrue(self.file_reader.is_valid_file(file_dir))

    def test_no_file(self):
        """This tests to ensure the class will reject a file that doesn't
        exist!"""
        file_dir = str.format("{}/testing_files/no_file",
                              self.current_dir).replace("\\", "/")
        self.assertFalse(self.file_reader.is_valid_file(file_dir))

    def test_empty_file(self):
        """This tests to ensure the class will read a class that's empty.
        It's not an issue if an empty file makes it through as it makes no
        difference to the program."""
        file_dir = str.format("{}/testing_files/test_file_empty.js",
                              self.current_dir).replace("\\", "/")
        self.assertTrue(self.file_reader.is_valid_file(file_dir))
コード例 #6
0
class View(Cmd):

    def __init__(self):
        super().__init__()
        self.intro = "\nwelcome to this cmd. type help_all for a list of " \
                     "commands,\nor for a specific command type 'help'" \
                     "followed by the command.\n" \
                     "Some commands require others to be completed first. If "\
                     "lost, use the help menu."
        self.prompt = "==>  "
        self.name = ""
        self.file_type = ""
        self.output_file_dir = ""
        self.selected_output_dir = False
        self.selected_file_type = False
        self.file_reader = FileReader()
        self.dir_reader = DirectoryReader()
        self.js_reader = JsParser()

    def do_set_name(self, arg):
        """This option allows to set your name, which can be added to the
        produced graphical documents. Type the command, followed by your
        name. Will accept all. """
        if arg != "":
            self.name = arg
            print(str.format("Name set to {}!", self.name))
        else:
            print(
                "Please provide a name! You do not have to do this step if "
                "you do not want to. It's ok, really.")

    def do_exit(self, arg):
        """This command closes the command line."""
        print("Goodbye! Won't miss you.")
        return True

    def do_set_output_dir(self, arg):
        output_dir = arg.replace("\\", "/")
        if self.dir_reader.is_valid_folder_dir(output_dir):
            self.output_file_dir = output_dir
            self.selected_output_dir = True
            print(str.format("Output directory set to [{}].",
                             self.output_file_dir))
        else:
            print("Invalid directory/input. Please try again.")

    def do_set_file_type(self, arg):
        """Use this function to set desired file type for the output
        document. Type the command followed by either -jpg or -j for jpg,
        and -p or -png for png. """
        valid_jpg = ["jpg", "-jpg", "-j", "j"]
        valid_png = ["png", "-png", "-p", "p"]
        arg = str.lower(arg)
        if arg in valid_jpg:
            self.file_type = "jpg"
            print("set file type to jpg!")
            self.selected_file_type = True
        elif arg in valid_png:
            self.file_type = "png"
            print("set file type to png!")
            self.selected_file_type = True
        else:
            print(
                "incorrect file type. Please type the command followed by "
                "either -jpg or -j for jpg, and -p or -png "
                "for png.")

    def do_instructions(self, arg):
        """Provides instructions for using the program. Complete commands in
        this order for best understanding. """
        print(
            "To start, you can choose to select a name. Example: set_name "
            "Loufeng *OPTIONAL STEP*")
        print(str.format(
            "Next, input the directory of the produced image files. Example: "
            "set_output_dir {} "
            " *NECESSARY STEP*", r"C:\Users\Luofeng\Desktop\umlfiles"))
        print(
            "Next, select your desired file type. Example: set_filetype -jpg "
            "*OPTIONAL STEP* - by default it's jpg")
        print(
            str.format("Finally, you can make the graphical document by "
                       "providing an input directory of a file or files."
                       " Example: create_uml {}*NECESSARY STEP*",
                       r"C:\Users\Luofeng\Desktop\jsfiles"))

    def do_help_all(self, arg):
        """This command provides a full, detailed list of all the commands."""
        print("set_name        <Luofeng>                     This command sets"
              " the creator name of the document. Type the command, followed"
              "by the desired name.")
        print("exit            <no parameters needed>        This command "
              "simply exits the program.")
        print("instructions    <no parameters needed>        This command"
              " simply provides a directional explanation to the order of"
              " commands.")
        print("set_output_dir  <C:/directoryA/output>        This command "
              "sets the desired folder where the output files will go.")
        print("set_file_type   <-jpg>, <-png>, <-j>, <-p>    This command "
              "sets the desired file type for the output.")
        print("create_uml      <C:/directoryA/DirectoryB>    This command is"
              " to be executed once a file type has been selected, and an "
              "output directory has been selected. Type the command followed"
              " by the input directory.")

    def do_create_uml(self, arg):
        """This command uses all the information provided so far and will
        produce a diagram based on input. """
        directory = arg.replace("\\", "/")
        if self.dir_reader.is_valid_js_dir(directory) \
                and self.selected_file_type\
                and self.selected_output_dir is True:
            for file in listdir(directory):
                file_dir = directory + "/" + file
                self.js_reader.set_js_file(
                    self.file_reader.get_file_contents(file_dir))
                self.js_reader.parse_js_file()
            for aClass in self.js_reader.all_my_classes:
                print(aClass)
        else:
            print(
                "Please select an output directory and/or provide a valid "
                "input directory.")

    def start(self):
        """Simple function which starts the program."""
        self.cmdloop()
コード例 #7
0
 def setUp(self):
     self.file_reader = FileReader()
     self.current_dir = getcwd()
コード例 #8
0
 def setUp(self):
     self.js_parser = JsParser()
     self.file_reader = FileReader()
     self.dir_reader = DirectoryReader()
     self.current_dir = getcwd()
コード例 #9
0
class TestJsParser(TestCase):

    def setUp(self):
        self.js_parser = JsParser()
        self.file_reader = FileReader()
        self.dir_reader = DirectoryReader()
        self.current_dir = getcwd()

    def test_basic_class(self):
        """Tests to see whether it can correctly read a js file with a
        basic class."""
        expected_class = {
            'name': 'TestClass',
            'attributes': ['name', 'allMySports'],
            'methods': ['constructor', 'testFunction']}
        file_dir = str.format("{}/testing_files/test_file_1.js",
                              self.current_dir).replace("\\", "/")
        js_file = self.file_reader.get_file_contents(file_dir)
        self.js_parser.set_js_file(js_file)
        self.js_parser.parse_js_file()
        actual_class = self.js_parser.all_my_classes[0]
        self.assertEqual(expected_class, actual_class)

    def test_class_no_methods_attributes(self):
        """Tests to see whether it can correctly read a js file with a class
        with no methods or attributes"""
        expected_class = {
            'name': 'TestClass',
            'attributes': [],
            'methods': []}
        file_dir = str.format("{}/testing_files/test_file_3.js",
                              self.current_dir).replace("\\", "/")
        js_file = self.file_reader.get_file_contents(file_dir)
        self.js_parser.set_js_file(js_file)
        self.js_parser.parse_js_file()
        actual_class = self.js_parser.all_my_classes[0]
        self.assertEqual(expected_class, actual_class)

    def test_class_no_methods(self):
        """Tests to see whether it can correctly read a js file with an empty
        constructor."""
        expected_class = {
            'name': 'TestClass',
            'attributes': ['attribute1', 'attribute2'],
            'methods': ['constructor']}
        file_dir = str.format("{}/testing_files/test_file_4.js",
                              self.current_dir).replace("\\", "/")
        js_file = self.file_reader.get_file_contents(file_dir)
        self.js_parser.set_js_file(js_file)
        self.js_parser.parse_js_file()
        actual_class = self.js_parser.all_my_classes[0]
        self.assertEqual(expected_class, actual_class)

    def test_multiple_classes(self):
        """Tests to see whether it can correctly read a js file with multiple
        classes."""
        expected_classes = [{
            'name': 'TestClass1',
            'attributes': ['attribute1', 'attribute2'],
            'methods': ['constructor']},
            {
                'name': 'TestClass2',
                'attributes': ['attribute1', 'attribute2'],
                'methods': ['constructor']},
            {
                'name': 'TestClass3',
                'attributes': ['attribute1', 'attribute2'],
                'methods': ['constructor']}]
        file_dir = str.format("{}/testing_files/test_file_2.js",
                              self.current_dir).replace("\\", "/")
        js_file = self.file_reader.get_file_contents(file_dir)
        self.js_parser.set_js_file(js_file)
        self.js_parser.parse_js_file()
        actual_classes = self.js_parser.all_my_classes
        self.assertEqual(expected_classes, actual_classes)

    def test_no_classes(self):
        """Tests to see whether it returns an empty list when there are
        no classes."""
        expected_classes = []
        file_dir = str.format("{}/testing_files/test_file_empty.js",
                              self.current_dir).replace("\\", "/")
        js_file = self.file_reader.get_file_contents(file_dir)
        self.js_parser.set_js_file(js_file)
        self.js_parser.parse_js_file()
        actual_classes = self.js_parser.all_my_classes
        self.assertEqual(expected_classes, actual_classes)

    def test_entire_class(self):
        """Tests to see whether it returns an empty list when the provided
        file is not compatible."""
        expected_classes = []
        file_dir = str.format("{}/testing_files/test_file_bad.js",
                              self.current_dir).replace("\\", "/")
        js_file = self.file_reader.get_file_contents(file_dir)
        self.js_parser.set_js_file(js_file)
        self.js_parser.parse_js_file()
        actual_classes = self.js_parser.all_my_classes
        self.assertEqual(expected_classes, actual_classes)

    def test_entire_dir(self):
        """Tests to see whether it can read an entire directory and extract
        all the classes."""
        expected_class_count = 4
        dir = str.format("{}/testing_files/test_four_classes",
                         self.current_dir).replace("\\", "/")
        self.dir_reader.set_directory(dir)
        for aDir in self.dir_reader.get_file_dirs():
            js_file = self.file_reader.get_file_contents(aDir)
            self.js_parser.set_js_file(js_file)
            self.js_parser.parse_js_file()
        actual_class_count = len(self.js_parser.all_my_classes)
        self.assertEqual(expected_class_count, actual_class_count)
コード例 #10
0
ファイル: test.py プロジェクト: zarix908/Crossword
 def setUp(self):
     self.__geometry_present = FileReader().read(
         "examples/exp1/geometry.txt")
     self.__words = FileReader().read("examples/exp1/words.txt")