Skip to content

Commit

Permalink
Add tests for SVG output in glycosylation process
Browse files Browse the repository at this point in the history
Extended the `test_cglycosylation` function to include assertions for SNFG output validation. Introduced XML parsing to check SVG structure, ensuring specific elements and attributes are present.
  • Loading branch information
Dialpuri committed Aug 8, 2024
1 parent 95d83ab commit 1cf61f3
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion package/tests/test_glycosylation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from pathlib import Path
from pprint import pprint
import xml.etree.ElementTree as ET

import gemmi
import sails
import pytest
Expand All @@ -20,13 +23,16 @@ def cglycan(data_base_path):


def test_cglycosylation(cglycan):
s, m, l = sails.glycosylate(*cglycan)
s, m, l, snfgs = sails.glycosylate(*cglycan)
assert s
assert m
assert l
assert snfgs

assert isinstance(s, gemmi.Structure)
assert isinstance(m, gemmi.Mtz)

# test log file
assert 'cycles' in l
assert 'date' in l

Expand Down Expand Up @@ -59,5 +65,28 @@ def test_cglycosylation(cglycan):
assert rsr_score > 0.9
assert dds_score < 0.75

# test snfg output
assert 1 in snfgs
c1 = snfgs[1]
expected_trp_key = "C-TRP-16"
assert expected_trp_key in c1

root = ET.fromstring(c1[expected_trp_key])
assert root.tag == '{http://www.w3.org/2000/svg}svg'
assert root.attrib['width'] == '1200'
assert root.attrib['height'] == '800'

line_count = len(root.findall('{http://www.w3.org/2000/svg}line'))
rect_count = len(root.findall('{http://www.w3.org/2000/svg}rect'))
circle_count = len(root.findall('{http://www.w3.org/2000/svg}circle'))
text_count = len(root.findall('{http://www.w3.org/2000/svg}text'))
tspan_count = len(root.findall('.//{http://www.w3.org/2000/svg}tspan'))

# Assert the expected counts
assert line_count == 3, f"Expected 3 <line> elements, but found {line_count}"
assert rect_count == 1, f"Expected 1 <rect> element, but found {rect_count}"
assert circle_count == 1, f"Expected 1 <circle> element, but found {circle_count}"
assert text_count == 3, f"Expected 3 <text> elements, but found {text_count}"
assert tspan_count == 1, f"Expected 1 <tspan> element, but found {tspan_count}"


0 comments on commit 1cf61f3

Please sign in to comment.