Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37 + test - the default xml was misformatted #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
16 changes: 10 additions & 6 deletions bioformats/omexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def xsd_now():
NS_RE = r"http://www.openmicroscopy.org/Schemas/(?P<ns_key>.*)/[0-9/-]"

default_xml = """<?xml version="1.0" encoding="UTF-8"?>
<OME xmlns="{ns_ome_default}s"
<OME xmlns="{ns_ome_default}"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2013-06 http://www.openmicroscopy.org/Schemas/OME/2012-03/ome.xsd">
xsi:schemaLocation="{ns_ome_default} {ns_ome_default}/ome.xsd">
<Image ID="Image:0" Name="default.png">
<AcquiredDate>%(DEFAULT_NOW)s</AcquiredDate>
<AcquiredDate>{DEFAULT_NOW}</AcquiredDate>
<Pixels DimensionOrder="XYCTZ"
ID="Pixels:0"
SizeC="1"
Expand All @@ -48,12 +48,16 @@ def xsd_now():
<Channel ID="Channel:0:0" SamplesPerPixel="1">
<LightPath/>
</Channel>
<BinData xmlns="%(NS_BINARY_FILE)s"
<BinData xmlns="{ns_binary_file}"
BigEndian="false" Length="0"/>
</Pixels>
</Image>
<StructuredAnnotations xmlns="{ns_sa_default}s"/>
</OME>""".format(ns_ome_default=NS_DEFAULT.format(ns_key='ome'), ns_sa_default=NS_DEFAULT.format(ns_key='sa'))
<StructuredAnnotations xmlns="{ns_sa_default}"/>
</OME>""".format(
ns_ome_default=NS_DEFAULT.format(ns_key='OME'),
ns_sa_default=NS_DEFAULT.format(ns_key='sa'),
ns_binary_file=NS_DEFAULT.format(ns_key="BinaryFile"),
DEFAULT_NOW=DEFAULT_NOW)

#
# These are the OME-XML pixel types - not all supported by subimager
Expand Down
18 changes: 18 additions & 0 deletions bioformats/tests/test_omexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

import datetime
import os
import re
import unittest
import urllib
import xml.dom
import xml.etree.ElementTree

import bioformats.omexml as O

Expand All @@ -32,6 +34,22 @@ def test_00_00_init(self):
self.assertEquals(o.root_node.tag, O.qn(o.get_ns("ome"), "OME"))
self.assertEquals(o.image_count, 1)

def test_00_01_ns_binary_file(self):
# regression test of issue #37
o = O.OMEXML()
xmlstr = o.to_xml()
tree = xml.etree.ElementTree.fromstring(xmlstr)
bfelements = tree.findall(".//*[@BigEndian]")
self.assertEqual(len(bfelements), 1)
#
# Try to find BinData with the namespace,
# http://www.openmicroscopy.org/Schemas/BinaryFile/YYYY-MM
#
match = re.match(
"\\{http://www.openmicroscopy.org/Schemas/BinaryFile/"
"\\d{4}-\\d{2}\\}BinData", bfelements[0].tag)
self.assertTrue(match is not None)

def test_01_01_read(self):
for xml in (self.GROUPFILES_XML, TIFF_XML):
o = O.OMEXML(xml)
Expand Down