Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aspython/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _createLibraryElement(self, libraryFolder, name, memory: str = 'UserROM', at
}
for attributeName in attributeOverrides:
attributes[attributeName] = attributeOverrides[attributeName]
element = ET.Element('LibraryObject', attrib=attributes)
element = ET.Element(self.nameSpaceFormatted + 'LibraryObject', attrib=attributes)
element.tail = "\n"
return element

Expand All @@ -83,7 +83,7 @@ def _createTaskElement(self, taskFolder, taskName, memory: str = 'UserROM') -> E
'Language': language,
'Debugging': 'true',
}
element = ET.Element('Task', attrib=attributes)
element = ET.Element(self.nameSpaceFormatted + 'Task', attrib=attributes)
element.tail = "\n"
return element

Expand Down
7 changes: 3 additions & 4 deletions aspython/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _addObjectElement(self, path):
def addDependency(self, *dependency):
deps_container = self.find('Dependencies')
if deps_container is None:
deps_container = ET.SubElement(self.root, 'Dependencies')
deps_container = ET.SubElement(self.root, self.nameSpaceFormatted + 'Dependencies')
for dependent in dependency:
if not isinstance(dependent, Dependency):
raise TypeError('Expected Dependency class got', type(dependent))
Expand Down Expand Up @@ -184,14 +184,13 @@ def _createPkgElement(path: str, tag: str) -> ET.Element:
element.tail = "\n"
return element

@staticmethod
def _createDependencyElement(dependency: Dependency):
def _createDependencyElement(self, dependency: Dependency):
attributes = {'ObjectName': dependency.name}
if dependency.minVersion:
attributes['FromVersion'] = dependency.minVersion
if dependency.maxVersion:
attributes['ToVersion'] = dependency.maxVersion
return ET.Element('Dependency', attributes)
return ET.Element(self.nameSpaceFormatted + 'Dependency', attributes)

@staticmethod
def _getXmlTag(package: ET.ElementTree) -> str:
Expand Down
41 changes: 41 additions & 0 deletions tests/test_deployment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Tests for aspython.deployment.SwDeploymentTable."""
from unittest.mock import patch

import pytest

from aspython.deployment import SwDeploymentTable

# Minimal cpu.sw with all 8 TaskClass slots and a Libraries section so that
# SwDeploymentTable.__init__ finds them all and skips its write-and-reload path.
_SW_XML = """\
<?xml version='1.0' encoding='utf-8'?>
<SwConfiguration xmlns="http://br-automation.co.at/AS/SwConfiguration" Version="1.0.0.0">
<TaskClass Name="Cyclic#1"/>
<TaskClass Name="Cyclic#2"/>
<TaskClass Name="Cyclic#3"/>
<TaskClass Name="Cyclic#4"/>
<TaskClass Name="Cyclic#5"/>
<TaskClass Name="Cyclic#6"/>
<TaskClass Name="Cyclic#7"/>
<TaskClass Name="Cyclic#8"/>
<Libraries/>
</SwConfiguration>"""

_PATCH_PATH = "aspython.deployment.getLibraryPathInPackage"
_PATCH_TYPE = "aspython.deployment.getLibraryType"


@pytest.fixture
def sw_table(tmp_path):
sw_path = tmp_path / "cpu.sw"
sw_path.write_text(_SW_XML, encoding="utf-8")
with patch(_PATCH_PATH, return_value="/fake/TestLib"), patch(_PATCH_TYPE, return_value="ANSIC"):
return SwDeploymentTable(str(sw_path))


def test_deploy_library_adds_entry(sw_table):
with patch(_PATCH_PATH, return_value="/fake/TestLib"), patch(_PATCH_TYPE, return_value="ANSIC"):
sw_table.deployLibrary("/some/Libraries/MyLibs", "TestLib")

# Newly deployed library is visible in-memory without a write+reload roundtrip.
assert "TestLib" in sw_table.libraries
28 changes: 28 additions & 0 deletions tests/test_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Tests for aspython.library.Library."""
import pytest

from aspython.library import Library
from aspython.models import Dependency

_LIBRARY_XML = """\
<?xml version='1.0' encoding='utf-8'?>
<Library xmlns="http://br-automation.co.at/AS/Library" SubType="ANSIC" Version="1.0.0.0" Description="">
<Files/>
</Library>"""


@pytest.fixture
def library_file(tmp_path):
lib_dir = tmp_path / "TestLib"
lib_dir.mkdir()
lby = lib_dir / "ANSIC.lby"
lby.write_text(_LIBRARY_XML, encoding="utf-8")
return Library(str(lby))


def test_add_dependency_roundtrip(library_file):
dep = Dependency(name="runtime", minVersion="", maxVersion="")
library_file.addDependency(dep)

# Newly added elements are visible in-memory without a write+reload roundtrip.
assert "runtime" in library_file.dependencyNames
Loading