MCPcopy
hub / github.com/qodo-ai/qodo-cover / get_code_language

Method get_code_language

cover_agent/UnitTestGenerator.py:90–123  ·  view source on GitHub ↗

Get the programming language based on the file extension of the provided source file path. Parameters: source_file_path (str): The path to the source file for which the programming language needs to be determined. Returns: str: The programming langu

(self, source_file_path)

Source from the content-addressed store, hash-verified

88 self.test_code = f.read()
89
90 def get_code_language(self, source_file_path):
91 """
92 Get the programming language based on the file extension of the provided source file path.
93
94 Parameters:
95 source_file_path (str): The path to the source file for which the programming language needs to be determined.
96
97 Returns:
98 str: The programming language inferred from the file extension of the provided source file path. Defaults to 'unknown' if the language cannot be determined.
99 """
100 # Retrieve the mapping of languages to their file extensions from settings
101 language_extension_map_org = get_settings().language_extension_map_org
102
103 # Initialize a dictionary to map file extensions to their corresponding languages
104 extension_to_language = {}
105
106 # Populate the extension_to_language dictionary
107 for language, extensions in language_extension_map_org.items():
108 for ext in extensions:
109 extension_to_language[ext] = language
110
111 # Extract the file extension from the source file path
112 extension_s = "." + source_file_path.rsplit(".")[-1]
113
114 # Initialize the default language name as 'unknown'
115 language_name = "unknown"
116
117 # Check if the extracted file extension is in the dictionary
118 if extension_s and (extension_s in extension_to_language):
119 # Set the language name based on the file extension
120 language_name = extension_to_language[extension_s]
121
122 # Return the language name in lowercase
123 return language_name.lower()
124
125 def check_for_failed_test_runs(self, failed_test_runs):
126 """

Callers 2

__init__Method · 0.95

Calls 1

get_settingsFunction · 0.90

Tested by

no test coverage detected