Ejemplo n.º 1
0
    def test_enum(self):
        module = formast.Module()
        self.parser.parse_string(
            """
<niftoolsxml>
  <enum name="AlphaFormat" storage="uint">
    An unsigned 32-bit integer, describing how transparency is handled in a texture.
    <option value="0" name="ALPHA_NONE">No alpha blending; the texture is fully opaque.</option>
    <option value="1" name="ALPHA_BINARY">Texture is either fully transparent or fully opaque.  There are no partially transparent areas.</option>
    <option value="2" name="ALPHA_SMOOTH">Full range of alpha values can be used from fully transparent to fully opaque including all partially transparent values in between.</option>
    <option value="3" name="ALPHA_DEFAULT">Use default setting.</option>
  </enum>
</niftoolsxml>
""", module)
        self.printer.module(module)
        nose.tools.assert_equal(
            str(self.printer), """\
enum:
 name: AlphaFormat
 base_name: uint
 stats:
  const:
   name: ALPHA_NONE
   value: 0
  const:
   name: ALPHA_BINARY
   value: 1
  const:
   name: ALPHA_SMOOTH
   value: 2
  const:
   name: ALPHA_DEFAULT
   value: 3""")
Ejemplo n.º 2
0
def test_codegen():
    module = formast.Module()
    with open_text("codegen/integers.xml") as stream:
        formast.XmlParser().parse_string(stream.read(), module)
    codegen_module = codegen.CodeGenModule()
    codegen_module.module(module)
    with open_text("codegen/integers.py") as stream:
        nose.tools.assert_multi_line_equal(stream.read(), str(codegen_module))
Ejemplo n.º 3
0
 def check(self, inp, out):
     module = formast.Module()
     inp = ("<niftoolsxml><compound name=\"Test\">"
            "<add type=\"uint\" name=\"test\" cond=\"" + inp + "\" />"
            "</compound></niftoolsxml>")
     self.parser.parse_string(inp, module)
     self.evaluator.module(module)
     nose.tools.assert_equal(len(self.evaluator.stack), 1)
     nose.tools.assert_equal(self.evaluator.stack[0], out)
Ejemplo n.º 4
0
    def test_conditioning(self):
        module = formast.Module()
        self.parser.parse_string(
            """
<niftoolsxml>
  <compound name="Test">
    <add name="Has Image" type="bool" />
    <add name="PS2 L" type="short" cond="Has Image" ver1="3.03" ver2="10.2.0.0" />
  </compound>
</niftoolsxml>
""", module)
        self.printer.module(module)
        # note: 50332416 = 0x03000300 and 167903232 = 0x0A020000
        nose.tools.assert_equal(
            str(self.printer), """\
class:
 name: Test
 stats:
  field:
   type: bool
   name: Has Image
  if:
   logical_and:
    logical_and:
     id: Has Image
     compare_ge:
      id: Version
      uint: 50332416
    compare_le:
     id: Version
     uint: 167903232
   then:
    stats:
     field:
      type: short
      name: PS2 L""")
Ejemplo n.º 5
0
 def check(self, inp, out):
     module = formast.Module()
     self.parser.parse_string(self.make_input_from_cond(inp), module)
     self.printer.module(module)
     nose.tools.assert_equal(str(self.printer), out)
Ejemplo n.º 6
0
        self.print_()

    def module_class(self, c):
        self.print_("class %s:" % c.name)
        self.indent += 1
        if c.stats:
            self.print_()
            self.print_("def __init__(self):")
            self.indent += 1
            codegeninit = CodeGenClassInit(parent=self)
            codegeninit.stats(c.stats.get())
            self.indent -= 1
            self.print_()
            self.print_("def read(self, stream):")
            self.indent += 1
            codegenread = CodeGenClassRead(parent=self)
            codegenread.stats(c.stats.get())
            self.indent -= 1
        else:
            self.print_("pass")
        self.indent -= 1


if __name__ == "__main__":
    module = formast.Module()
    with open("integers.xml", "rb") as stream:
        formast.XmlParser().parse_string(stream.read(), module)
    codegen = CodeGenModule()
    codegen.module(module)
    print(codegen)
Ejemplo n.º 7
0
def get_runtime():
    module = formast.Module()
    with open_text("codegen/integers.xml") as stream:
        formast.XmlParser().parse_string(stream.read(), module)
    return runtime.RuntimeModule(module)