Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Fix python indent #9

wants to merge 7 commits into from

Conversation

Montagon
Copy link
Collaborator

No description provided.

@github-actions
Copy link

FormaLM has performed a code analysis and generated a report. Please check the Security report for more information.

src/scoreHelpers.py Show resolved Hide resolved
src/scoreHelpers.py Show resolved Hide resolved
src/scoreHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/configHelpers.py Fixed Show fixed Hide fixed
src/scoreHelpers.py Show resolved Hide resolved
src/scoreHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/scoreHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/configHelpers.py Fixed Show fixed Hide fixed
src/scoreHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/scoreHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
@xebia-functional xebia-functional deleted a comment from github-actions bot Jul 11, 2023
@xebia-functional xebia-functional deleted a comment from github-actions bot Jul 11, 2023
src/configHelpers.py Fixed Show fixed Hide fixed
@github-actions
Copy link

FormaLM has performed a code analysis and generated a report. Please check the Security report for more information.

src/scoreHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
src/configHelpers.py Show resolved Hide resolved
Comment on lines +18 to +23
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

Recommended tests: readConfig in src/configHelpers.py
@github-actions
Copy link

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):

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):

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):

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants