Skip to content

Use a temporary file for testing defaults.ini content loading in test_pypi_sourcecode_analyzer.py #1108

Description

@tromai

Description

In this test module - https://github.com/oracle/macaron/blob/612e27ec347e7e073311b65a32b9eec8c6ba7d5c/tests/malware_analyzer/pypi/test_pypi_sourcecode_analyzer.py, we are mocking the defaults object to test some behaviors relating to some source code analysis configuration in defaults.ini.

Expectation

In this module https://github.com/oracle/macaron/blob/44dbf0acbd3dcb9f577db97b5c6876cfb8c87957/tests/config/test_defaults.py we put the defaults.ini content into a temporary file and load from it.
This is an example

user_config_path = os.path.join(tmp_path, "config.ini")
with open(user_config_path, "w", encoding="utf-8") as user_config_file:
user_config_file.write(user_config_input)
load_defaults(user_config_path)
results = defaults.get_list(section="test.list", option="list", delimiter=delimiter, strip=strip)
assert results == expect

which can remove the need for mocking and keep the defaults.ini in the test definition itself. Perhaps we can rewrite the tests in test_pypi_sourcecode_analyzer.py to use this approach instead.

Metadata

Metadata

Assignees

Labels

testsEnhancement of tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions