예제 #1
0
    def test_replace_logical_ops(self):
        """Tests Python.test_replace_logical_ops"""

        # Create test set
        test_set = [
            "and_str and or_str or not_str and not and_or_not_str",
            "name and uid or reg_no and not unknown and not(std < 1)",
            "&&_str and ||_str or n!_str and u! &&_||_!_str"
        ]

        # Create expected results test set
        res_set = [
            "and_str && or_str || not_str && !and_or_not_str",
            "name && uid || reg_no && !unknown && !(std < 1)",
            "&&_str && ||_str || n!_str && u! &&_||_!_str"
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test from conversion
            self.assertEqual(Python().replace_logical_ops(test_set[i], "to"),
                             res_set[i])

            # Test to conversion
            self.assertEqual(Python().replace_logical_ops(res_set[i], "from"),
                             test_set[i])
예제 #2
0
    def test_is_interface(self):
        """Tests Python.is_interface"""

        # Create test set
        test_set = [
            (self.file, 6),
            (self.file, 11),
            (self.file, 1),
            (self.file, 17),
        ]

        # Create expected results test set
        res_set = [
            True,
            True,
            False,
            False
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().is_interface(*test_set[i]),
                             res_set[i])
예제 #3
0
    def test_get_type(self):
        """Tests Python.get_type"""

        # Create test set
        test_set = [
            "0",
            "213.456",
            "23j",
            "'string'",
            '"Double quote string"',
            "[0, 1, 2, 3]",
            "('This', 'is', 'a', 'tuple')",
            "{'key': 'value'}"
        ]

        # Create expected results test set
        res_set = [
            "int",
            "float",
            "complex",
            "str",
            "str",
            "list",
            "tuple",
            "dict"
        ]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_type(test_set[i]),
                             res_set[i])
예제 #4
0
    def test_convert_class(self):
        """Tests Python.convert_class"""

        # Create test set
        test_set = [
            ("public", "ClassName", ["ParentClass"], ["SuperIntr", "MyIntr"]),
            ("public", "MyClass", ["SuperClass"], ["RandIntr"]),
            ("public", "RandClass", ["MyClass"], []),
            ("public", "MyOwnClass", [], ["MyOwnIntr"]),
            ("public", "BareClass", [], [])
        ]

        # Create expected results test set
        res_set = [
            ["class ClassName(ParentClass, SuperIntr, MyIntr):",
             '"""SuperIntr: interface',
             'MyIntr: interface"""'],
            ["class MyClass(SuperClass, RandIntr):",
             '"""RandIntr: interface"""'],
            ["class RandClass(MyClass):"],
            ["class MyOwnClass(MyOwnIntr):",
             '"""MyOwnIntr: interface"""'],
            ["class BareClass:"]
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().convert_class(*test_set[i]),
                             (res_set[i], []))
예제 #5
0
    def test_convert_for(self):
        """Tests Python.convert_for"""

        # Create test set
        test_set = [
            ("i", "0", "10", "1", None),
            ("i", "2", "10", "1", None),
            ("i", "0", "10", "2", None),
            ("i", "0", "Array.length", "1", "array"),
            ("i", "2", "Array.length", "2", "array"),
        ]

        # Create expected results test set
        res_set = [
           "for i in range(10):",
           "for i in range(2, 10):",
           "for i in range(0, 10, 2):",
           "for i in array:",
           "for i in array[2::2]:"
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().convert_for(*test_set[i]),
                             ([res_set[i]], []))
예제 #6
0
    def test_get_list_slice_vars(self):
        """Tests Python.get_list_slice_vars"""

        # Create test set
        test_set = [
            "array[:10]",
            "my_array[4:]",
            "dual_in_arr[2:10]",
            "step_arr[0:10:5]"
        ]

        # Create expected results test set
        res_set = [
            ("array", "0", "10", "1"),
            ("my_array", "4", "Array.length", "1"),
            ("dual_in_arr", "2", "10", "1"),
            ("step_arr", "0", "10", "5")
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_list_slice_vars(test_set[i]),
                             res_set[i])
예제 #7
0
    def test_convert_if(self):
        """Tests Python.convert_if"""

        # Create test set
        test_set = [
            "name && uid || reg_no && !unknown && !(std < 1)",
            "_!name && ||uid || |||| && &&&&&&&",
            "!!",
            "!(!)"
        ]

        # Create expected results test set
        res_set = [
           "if name and uid or reg_no and not unknown and not(std < 1):",
           "if _!name and ||uid or |||| and &&&&&&&:",
           "if not !:",
           "if not(not):"
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().convert_if(test_set[i], "if"),
                             ([res_set[i]], []))
예제 #8
0
    def test_convert_interface(self):
        """Tests Python.convert_interface"""

        # Create test set
        test_set = [
            ("public", "IntrName", ["ParentIntr", "SuperIntr"]),
            ("private static", "RandIntr", ["MyIntr"]),
            ("public", "Interface", []),
        ]

        # Create expected results test set
        res_set = [
            ["class IntrName(ParentIntr, SuperIntr):",
             '"""class type: interface',
             "ParentIntr: interface", 
             'SuperIntr: interface"""'],
            ["class RandIntr(MyIntr):",
             '"""class type: interface',
             'MyIntr: interface"""'],
            ["class Interface:",
             '"""class type: interface"""']
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().convert_interface(*test_set[i]),
                             (res_set[i], [])) 
예제 #9
0
    def test_get_while_condition(self):
        """Tests Python.get_while_condition"""

        # Create test set
        test_set = [ 
            (self.file, 43),
        ]

        # Create expected results test set
        res_set = [
            ("running && !stop", [], []),
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_while_condition(*test_set[i]),
                             res_set[i])
예제 #10
0
    def test_get_function_definition(self):
        """Tests Python.get_function_definition"""

        # Create test set
        test_set = [
            (self.file, 22),
            (self.file, 40)
        ] 
        # Create expected results test set
        res_set = [
            ("private", "void", "__my_func", [["self", "Cls.Obj"], ["name", "str"]], [], []),
            ("public", "void", "main", [], [], ['staticmethod', 'main = my_dec(main)']),
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_function_definition(*test_set[i]),
                             res_set[i])
예제 #11
0
    def test_get_if_condition(self):
        """Tests Python.get_if_condition"""

        # Create test set
        test_set = [
            (self.file, 23),
            (self.file, 24)
        ]

        # Create expected results test set
        res_set = [
            ("!occupied && !(processes_running > 500)", "if", [" pass"], []),
            ('(name != "" && name) || default', "else if", [], [])
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_if_condition(*test_set[i]),
                             res_set[i])
예제 #12
0
    def test_convert_decorator(self):
        """Tests Python.convert_decorator"""

        # Create test set
        test_set = [
            ("@my_dec", "my_func"),
            ("@staticmethod", "my_static_func")
        ]

        # Create expected results test set
        res_set = [
            "my_func = my_dec(my_func)",
            "my_static_func = staticmethod(my_static_func)"
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().convert_decorator(*test_set[i]),
                             [res_set[i]])
예제 #13
0
    def test_convert_while(self):
        """Tests Python.convert_while"""

        # Create test set
        test_set = [
            "count < 100 && !(count == 0 || count < 0) && !error",
            "!user_input.valid() && !(user_input.quit || one_shot)"
        ]

        # Create expected results test set
        res_set = [
            "while count < 100 and not(count == 0 or count < 0) and not error:",
            "while not user_input.valid() and not(user_input.quit or one_shot):"
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().convert_while(test_set[i]),
                             ([res_set[i]], []))
예제 #14
0
    def test_get_doc_str(self):
        """Tests Python.get_doc_str"""

        # Create test set
        test_set = [
            (self.file, 6),
            (self.file, 11)
        ]

        # Create expected results test set
        res_set = [
            ["class type: interface"],
            ["class type: interface", "MyIntr: interface"]
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_doc_str(*test_set[i]),
                             res_set[i])
예제 #15
0
    def test_make_function_definition(self):
        """Tests Python.make_function_definition"""

        # Create test set
        test_set = [
            ("void", "main", []),
            ("int", "func_name", [["var", 'int']])
        ]

        # Create expected results test set
        res_set = [
            "def main() -> 'None':",
            "def func_name(var: 'int') -> 'int':"
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().make_function_definition(*test_set[i]),
                             res_set[i])
예제 #16
0
    def test_parse_function_definition(self):
        """Tests Python.parse_function_definition"""

        # Create test set
        test_set = [
            (self.file, 40, "def main", "):"),
            (self.file, -1, "def func_name", "var: 'int') -> 'int':")
        ]

        # Create expected results test set
        res_set = [
           ("void", "main", [], ["staticmethod", "main = my_dec(main)"]),
           ("int", "func_name", [["var", 'int']], []) 
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().parse_function_definition(*test_set[i]),
                             res_set[i])
예제 #17
0
    def test_get_interface_definition(self):
        """Tests Python.get_interface_definition"""

        # Create test set
        test_set = [
            (self.file, 6),
            (self.file, 11)
        ]

        # Create expected results test set
        res_set = [
            ("public", "MyIntr", [], [], []),
            ("public", "ChildIntr", ["MyIntr"], [], []),
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_interface_definition(*test_set[i]),
                             res_set[i])
예제 #18
0
    def test_convert_method(self):
        """Tests Python.convert_method"""

        # Create test set
        test_set = [
            ("public static", "void", "main", []),
            ("public", "String", "my_func", [["var", "float"]])
        ]

        # Create expected results test set
        res_set = [
           ["@staticmethod", "def main() -> 'None':"],
           ["def my_func(var: 'float') -> 'String':"]
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().convert_method(*test_set[i]),
                             (res_set[i], []))
예제 #19
0
    def install_process_cached(self, package_json, dependencies, args):
        for pkgname, versions in dependencies:
            package_cache_path = path.join(APP_CACHE_DIR, pkgname)
            git_package_cache_path = path.join(package_cache_path, APP_GIT_FOLDER_NAME)
            try:
                os.makedirs(package_cache_path)
            except OSError:
                pass

            # init repo
            if not path.isdir(git_package_cache_path):
                Python().execute_command(command='init', args=['-p', package_cache_path, '-i'])
            repo = Repository(git_package_cache_path)

            cached_versions = utils.get_commit_list(repo)

            # clean up all version but the last one
            for version in versions:
                if version not in cached_versions:
                    self.clean(package_cache_path)
                    self.install_package_cached(repo, pkgname, version, package_cache_path)
예제 #20
0
    def test_get_class_name(self):
        """Tests Python.get_class_name"""

        # Create test set
        test_set = [
            (self.file, 22),
            (self.file, 14),
            (self.file, 8)
        ]

        # Create expected results test set
        res_set = [
           "ChildCls",
           "ChildIntr",
           "MyIntr"
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_class_name(*test_set[i]),
                             res_set[i])
예제 #21
0
    def test_get_for_iterations(self):
        """Tests Python.get_for_iterations"""

        # Create test set
        test_set = [
            (self.file, 30),
            (self.file, 32),
            (self.file, 34)
        ]

        # Create expected results test set
        res_set = [
            ("Array.data_type i", "0", "Array.length", "1", "array", [], []),
            ("int i", "5", "count", "1", None, [], []),
            ("int i", "0", "count", "2", None, [], [])
        ]
 
        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Python().get_for_iterations(*test_set[i]),
                             res_set[i])
예제 #22
0

def get_main_file(path):
    for filename in os.listdir(path):
        if filename.startswith(MAIN_FILE_NAME + "."):
            return filename
    return None


if __name__ == '__main__':

    # Pop file name
    argv.pop(0)

    # If no command specified, exec help for main
    if len(argv) == 0:
        Python().execute_command(args=argv, command="main")
        sys.exit(1)

    commands = get_commands()

    # Get the command
    command = argv[0]

    if command in commands:
        argv.pop(0)

        Python().execute_command(command=command)
    else:
        Python().execute_command(command="main")
        # print 'Unrecognized command.'
예제 #23
0
def codestructuremaker_main():
    # loggin system
    logging.basicConfig(filename='log', level=logging.DEBUG)

    # Initiate the parser
    parser = argparse.ArgumentParser(
        description="Create default code project structure automaticaly")
    valid_licenses = [None, "mit"]
    valid_languages = ["python", "webproject", "cpp", "c", "nodejs"]

    # Add long and short argument
    parser.add_argument("--language",
                        "-l",
                        choices=valid_languages,
                        help="Set the language of the project")
    parser.add_argument("--name", "-n", help="Set the name of the project")
    parser.add_argument("--license",
                        "-li",
                        default=None,
                        choices=valid_licenses,
                        help="Set the license of the project")
    #parser.add_argument("--path", "-p", help="Set the path of the project")

    # Read arguments from the command line
    args = parser.parse_args()

    if len(sys.argv) == 1:
        from pyfiglet import Figlet
        f = Figlet(font='slant')
        print(f.renderText('CSM'))
        print("Language list")
        for language in valid_languages:
            print("- " + language)
        while True:
            args.language = input("Please chose language: ")
            if args.language not in valid_languages:
                print("Not supported language")
            else:
                break
        args.name = input("Please chose projectName: ")

        args.license = input("Please chose license: (defaul: None) ")
        if args.license not in valid_licenses:
            print("Not supported license, we use default")
            args.license = None
        if args.license == "":
            print("Not supported license, we use default")
            args.license = None

    # Check args
    if (args.language and args.name):
        if args.language == "python":
            from languages.python import Python
            Python(args.name, args.license)
        if args.language == "webproject":
            from languages.webproject import WebProject
            WebProject(args.name, args.license)
        if args.language == "cpp":
            from languages.cpp import CPP
            CPP(args.name, args.license)
        if args.language == "c":
            from languages.c import C
            C(args.name, args.license)
        if args.language == "nodejs":
            from languages.nodejs import Nodejs
            Nodejs(args.name, args.license)
    else:
        print("Language and project name are compulsary")

    return 0