Example #1
0
def test_no_multiple_format_understanding(test_image):
  """ for a given image file, walks the whole tree of Format objects.
  If the file can be understood by multiple Format objects at the same
  inheiritance level, it will return False, otherwise True."""

  Registry.setup()

  global any_understood, highest_level, found_a_repeat

  any_understood = False

  def recurse(format, image_file, level):
    global any_understood, highest_level, found_a_repeat
    for child in format._children:
      try:
        understood = child.understand(image_file)
      except Exception as e:
        understood = False
      if understood:
        any_understood = True
        print ("level: %d" % (level), child.__name__)
        found_a_repeat = level == highest_level
        highest_level = level
        recurse(child, image_file, level + 1)

  level = 1
  highest_level = 0
  found_a_repeat = False
  for format in Registry._formats:
    try:
      understood = format.understand(test_image)
    except Exception as e:
      understood = False
    if understood:
      any_understood = True
      print ("level: %d" % (level), format.__name__)
      found_a_repeat = level == highest_level
      highest_level = 1
      recurse(format, test_image, level + 1)

  assert not found_a_repeat, "image file understood by multiple Format objects"
  # It's a failure if nothing could understand this file
  assert any_understood, "No formatter could be found"
Example #2
0
from __future__ import absolute_import, division, print_function
from dxtbx.format.Registry import Registry

Registry.setup()
import sys


def print_class(classobj, filename=None, depth=1):
    if filename is None:
        print("% 5d" % depth, "  " * depth, classobj.__name__)
    else:
        try:
            ok = classobj.understand(filename)
        except Exception:
            ok = False
        if ok:
            print("% 5d" % depth, "  " * depth, classobj.__name__)
        else:
            return
    for child in classobj._children:
        print_class(child, filename, depth + 1)


def show_registry(filename=None):
    if filename is None:
        extrabit = ""
    else:
        extrabit = " that understand image %s" % filename
    print(
        "Showing hierarchy of classes in the dxtbx registry%s. The root classes are shown with depth of 1, and subclasses are shown indented and with a higher depth number."
        % extrabit)