-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix python indent #9
base: main
Are you sure you want to change the base?
Conversation
FormaLM has performed a code analysis and generated a report. Please check the Security report for more information. |
FormaLM has performed a code analysis and generated a report. Please check the Security report for more information. |
def readConfig(toClass = True): | ||
with open("application.conf", 'r') as configFile: | ||
return json.load(configFile) | ||
if toClass: | ||
return json.load(configFile, object_hook=instrumentDecoder) | ||
else: | ||
return json.load(configFile) |
Check notice
Code scanning / Formalm
Recommended tests: readConfig in src/configHelpers.py
FormaLM has performed a code analysis and generated a report. Please check the Security report for more information. |
if toClass: | ||
return json.load(configFile, object_hook=instrumentDecoder) | ||
else: | ||
return json.load(configFile) | ||
|
||
def getSearchElements(config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function getSearchElements
needs to be tested.
FormaLM has generated the following test:
- Test the function with an empty config
def test_empty_config():
config = []
result = getSearchElements(config)
assert result == []
- Test the function with a config containing one element
def test_single_element_config():
config = [{'name': 'element1'}]
result = getSearchElements(config)
assert result == ['element1']
- Test the function with a config containing multiple elements
def test_multiple_elements_config():
config = [{'name': 'element1'}, {'name': 'element2'}, {'name': 'element3'}]
result = getSearchElements(config)
assert result == ['element1', 'element2', 'element3']
- Test the function with a config containing elements with different names
def test_different_names_config():
config = [{'name': 'element1'}, {'name': 'element2'}, {'name': 'element3'}, {'name': 'element4'}]
result = getSearchElements(config)
assert result == ['element1', 'element2', 'element3', 'element4']
- Test the function with a config containing elements with the same name
def test_same_names_config():
config = [{'name': 'element1'}, {'name': 'element1'}, {'name': 'element1'}]
result = getSearchElements(config)
assert result == ['element1', 'element1', 'element1']
- Test the function with a config containing elements with missing 'name' key
def test_missing_name_key_config():
config = [{'name': 'element1'}, {'name': 'element2'}, {'other_key': 'element3'}]
result = getSearchElements(config)
assert result == ['element1', 'element2']
- Test the function with a config containing elements with empty 'name' value
def test_empty_name_value_config():
config = [{'name': 'element1'}, {'name': '', 'other_key': 'element2'}, {'name': 'element3'}]
result = getSearchElements(config)
assert result == ['element1', '', 'element3']
def instrumentDecoder(instrumentDict): | ||
return namedtuple('X', instrumentDict.keys())(*instrumentDict.values()) | ||
|
||
def readConfig(toClass = True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function readConfig
needs to be tested.
FormaLM has generated the following test:
- Test reading config file with toClass=True
def test_read_config_to_class():
# Create a temporary config file
with open('temp_config.conf', 'w') as temp_file:
temp_file.write('{"key": "value"}')
# Call the function
result = readConfig(toClass=True)
# Check if the result is a dictionary
assert isinstance(result, dict)
# Check if the result contains the expected key-value pair
assert result == {'key': 'value'}
# Remove the temporary config file
os.remove('temp_config.conf')
- Test reading config file with toClass=False
def test_read_config_to_object():
# Create a temporary config file
with open('temp_config.conf', 'w') as temp_file:
temp_file.write('{"key": "value"}')
# Call the function
result = readConfig(toClass=False)
# Check if the result is a dictionary
assert isinstance(result, dict)
# Check if the result contains the expected key-value pair
assert result == {'key': 'value'}
# Remove the temporary config file
os.remove('temp_config.conf')
- Test reading non-existent config file
def test_read_nonexistent_config():
# Call the function
with pytest.raises(FileNotFoundError):
readConfig()
|
||
def getSearchElements(config): | ||
res = [] | ||
for row in config: | ||
res.append(row['name']) | ||
res.append(row.name) | ||
return res | ||
|
||
def getElementsWithURL(config, urls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function getElementsWithURL
needs to be tested.
FormaLM has generated the following test:
- Test case where config and urls have the same length
def test_same_length():
config = [{'key': 'value'}, {'key': 'value'}, {'key': 'value'}]
urls = ['url1', 'url2', 'url3']
expected_result = [{'key': 'value', 'url': 'url1'}, {'key': 'value', 'url': 'url2'}, {'key': 'value', 'url': 'url3'}]
assert getElementsWithURL(config, urls) == expected_result
- Test case where config is empty
def test_empty_config():
config = []
urls = ['url1', 'url2', 'url3']
expected_result = []
assert getElementsWithURL(config, urls) == expected_result
- Test case where urls is empty
def test_empty_urls():
config = [{'key': 'value'}, {'key': 'value'}, {'key': 'value'}]
urls = []
expected_result = [{'key': 'value'}, {'key': 'value'}, {'key': 'value'}]
assert getElementsWithURL(config, urls) == expected_result
- Test case where config and urls have different lengths
def test_different_lengths():
config = [{'key': 'value'}, {'key': 'value'}, {'key': 'value'}]
urls = ['url1', 'url2']
expected_result = [{'key': 'value', 'url': 'url1'}, {'key': 'value', 'url': 'url2'}, {'key': 'value'}]
assert getElementsWithURL(config, urls) == expected_result
- Test case where config and urls have different lengths and config is empty
def test_different_lengths_empty_config():
config = []
urls = ['url1', 'url2']
expected_result = []
assert getElementsWithURL(config, urls) == expected_result
No description provided.