ersilia-os / ersilia-pack

Module to pack Ersilia models with FastAPI
GNU General Public License v3.0
1 stars 6 forks source link

Add tests for DockerfileInstallParser class #26

Open DhanshreeA opened 2 weeks ago

OlawumiSalaam commented 2 weeks ago

@DhanshreeA please can I work on this?

OlawumiSalaam commented 1 week ago

@DhanshreeA I am still waiting for your approval to work on this issue. Thank you.

DhanshreeA commented 1 week ago

Hey @OlawumiSalaam please go ahead!

GemmaTuron commented 1 week ago

Hi @OlawumiSalaam and @DhanshreeA

Please do not work on issues that do not have any description. Detail the steps and which tests will be added in this work before starting to work on the issue to that anyone who lands here can follow easily. Thanks!

OlawumiSalaam commented 1 week ago

@GemmaTuron I outlined the tests and steps I added in the Pull Request. I will outline it here as well. Thank you.

OlawumiSalaam commented 1 week ago

This task is to test parser module with as many edge cases as possible. For parser.py module we want to test Add tests for DockerfileInstallParser class. the existing parser module provides classes to parse installation instructions from YAML files and Dockerfiles, generate bash scripts from these instructions, and convert metadata from YAML format to JSON. The parser.py has the following classes:

InstallParser: An abstract base class for handling installation files. It defines the core functionality for getting the Python executable path, checking for conda commands and converting commands to a bash script. It also writes the generated bash script to a file. YAMLInstallParser: Inherits fromInstallParser and is designed to parseinstall.yml file for Python version and installation commands. It expects the YAML file to have a structure that includes Python version and installation commands. DockerfileInstallParser: Inherits from InstallParser and parses a Dockerfile for Python version and installation commands. It extractsRUN pip or RUN conda commands and converts them into a list format. MetadataYml2JsonConverter: Converts metadata from YAML to JSON. It allows flexible handling of YAML keys and ensures they are converted to JSON in a consistent format. This task adds unit tests for the DockerfileInstallParser class within the Ersilia-pack. The ensures that the class can accurately parse Dockerfiles forpip and conda installation commands and handle various command structures. For context I will add following tests:

DhanshreeA commented 1 week ago

Thanks @OlawumiSalaam ! Here's an example model with an install.yml file that you can use as a test fixture to work on this. And you can any other Ersilia model, for example, this one to use its Dockerfile as a text fixture.

OlawumiSalaam commented 5 days ago

@DhanshreeA I have added tests for DockerfileInstallParser class. The test_dockerfile_install_parser.py module contains unit tests for the DockerfileInstallParser class defined in the dockerfile_install_parser.py module. I used the pytest framework to validate that installation commands are correctly parsed from a Dockerfile and also check that the parser correctly interprets Python, pip and conda commands. Here a detailed description of the test is found here for your review. Thank you.

OlawumiSalaam commented 5 days ago

Additional Task

I had refactored the parsers.py module into focused classes( module ). Aside dockerfile_install_parser.py, the other modules and their functionality are stated below:

  1. install_parser.py: The InstallParser class is a base class used to parse installation commands from configuration files (YAMLand Dockerfiles) and convert them into a bash script that can be executed. It provides abstract methods (i.e placeholders) to be implemented by other classes(subclasses) . This help us avoid code duplication and ensures that the shared functionality is maintained in one place.

  2. yaml_install_parser.py: The YAMLInstallParser class is a subclass of InstallParser designed for parsing installation commands from install.yml files. It loads YAML data upon initialization and extracts the Python version and installation commands. The class also inherits functionality from InstallParser to convert these commands into executable bash scripts, allowing for easy execution of the installation steps defined in the YAML file.

  3. metadata_yml2json_converter.py: The MetadataYml2JsonConverter class is for converting metadata stored as YAML to JSON format. It reads a YAML file and loads its contents. It has methods to convert various data types ensuring that single values are correct and that the lists are handled correctly. The convert method organizes the data into an ordered dictionary, extracts, specific keys such as "Identifier", "Slug", and "Title" and writes the structured data to a specified JSON file.

I added tests for YAMLInstallParser class

I added tests to check that YAMLInstallParser class behaves as expected and handles the specified YAML structure correctly. The following tests were implemented:

  1. test_load_yaml: This function verifies that the YAML file is loaded correctly and checks for the presence of "python" and "commands."

  2. test_get_python_version: This function tests the _get_python_versionmethod to ensure it correctly parses the specified Python version from the loadedYAML data.

  3. test_get_commands: This function checks the_get_commands method, confirming that it accurately extracts the installation commands from the YAML file. It validates both the number of commands and their content.

I ran a test with the referenced install.yml file. The test output can be found in the attached log file test_yaml_install_parser_output3.log

@DhanshreeA Please, can I open a Pull Request for a detailed explanation of the implementation for your review? Thank you.