def test_get_build_packages(self): plugin = PythonPlugin(part_name="my-part", options=lambda: None) self.assertThat( plugin.get_build_packages(), Equals({"findutils", "python3-venv", "python3-dev"}), )
def test_get_build_environment(): plugin = PythonPlugin(part_name="my-part", options=lambda: None) assert plugin.get_build_environment() == { "PATH": "${SNAPCRAFT_PART_INSTALL}/bin:${PATH}", "SNAPCRAFT_PYTHON_INTERPRETER": "python3", "SNAPCRAFT_PYTHON_VENV_ARGS": "", }
def test_get_build_environment(self): plugin = PythonPlugin(part_name="my-part", options=lambda: None) self.assertThat( plugin.get_build_environment(), Equals({ "SNAPCRAFT_PYTHON_INTERPRETER": "python3", "SNAPCRAFT_PYTHON_VENV_ARGS": "", }), )
def test_get_build_commands(): class Options: constraints = list() requirements = list() python_packages = list() plugin = PythonPlugin(part_name="my-part", options=Options()) assert (plugin.get_build_commands() == [ '"${SNAPCRAFT_PYTHON_INTERPRETER}" -m venv ${SNAPCRAFT_PYTHON_VENV_ARGS} "${SNAPCRAFT_PART_INSTALL}"', 'SNAPCRAFT_PYTHON_VENV_INTERP_PATH="${SNAPCRAFT_PART_INSTALL}/bin/${SNAPCRAFT_PYTHON_INTERPRETER}"', "[ -f setup.py ] && pip install -U .", ] + _FIXUP_BUILD_COMMANDS)
def test_get_build_commands_with_all_properties(): class Options: constraints = ["constraints.txt"] requirements = ["requirements.txt"] python_packages = ["pip", "some-pkg; sys_platform != 'win32'"] plugin = PythonPlugin(part_name="my-part", options=Options()) assert (plugin.get_build_commands() == [ '"${SNAPCRAFT_PYTHON_INTERPRETER}" -m venv ${SNAPCRAFT_PYTHON_VENV_ARGS} "${SNAPCRAFT_PART_INSTALL}"', 'SNAPCRAFT_PYTHON_VENV_INTERP_PATH="${SNAPCRAFT_PART_INSTALL}/bin/${SNAPCRAFT_PYTHON_INTERPRETER}"', "pip install -c 'constraints.txt' -U pip 'some-pkg; sys_platform != '\"'\"'win32'\"'\"''", "pip install -c 'constraints.txt' -U -r 'requirements.txt'", "[ -f setup.py ] && pip install -c 'constraints.txt' -U .", ] + _FIXUP_BUILD_COMMANDS)
def test_schema(): assert PythonPlugin.get_schema() == { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "additionalProperties": False, "properties": { "constraints": { "default": [], "items": { "type": "string" }, "type": "array", "uniqueItems": True, }, "python-packages": { "default": [], "items": { "type": "string" }, "type": "array", "uniqueItems": True, }, "requirements": { "default": [], "items": { "type": "string" }, "type": "array", "uniqueItems": True, }, }, "type": "object", }
def test_get_build_commands_with_all_properties(): class Options: constraints = ["constraints.txt"] requirements = ["requirements.txt"] python_packages = ["pip"] plugin = PythonPlugin(part_name="my-part", options=Options()) plugin.get_build_commands() == [ '"${SNAPCRAFT_PYTHON_INTERPRETER}" -m venv ${SNAPCRAFT_PYTHON_VENV_ARGS} ' '"${SNAPCRAFT_PART_INSTALL}"', '. "${SNAPCRAFT_PART_INSTALL}/bin/activate"', "pip install -c 'constraints.txt' -U pip", "pip install -c 'constraints.txt' -U -r 'requirements.txt'", "[ -f setup.py ] && pip install -c 'constraints.txt' -U .", ] + _FIXUP_BUILD_COMMANDS
def test_get_build_commands(self): class Options: constraints = list() requirements = list() python_packages = list() plugin = PythonPlugin(part_name="my-part", options=Options()) self.assertThat( plugin.get_build_commands(), Equals([ '"${SNAPCRAFT_PYTHON_INTERPRETER}" -m venv ${SNAPCRAFT_PYTHON_VENV_ARGS} ' '"${SNAPCRAFT_PART_INSTALL}"', '. "${SNAPCRAFT_PART_INSTALL}/bin/activate"', "[ -f setup.py ] && pip install -U .", ] + self._FIXUP_BUILD_COMMANDS), )
def test_get_build_packages(): plugin = PythonPlugin(part_name="my-part", options=lambda: None) assert plugin.get_build_packages() == { "findutils", "python3-venv", "python3-dev" }