# Path: kiel/protocol/primitives.py
# class Primitive(object):
# class VariablePrimitive(Primitive):
# class Int8(Primitive):
# class Int16(Primitive):
# class Int32(Primitive):
# class Int64(Primitive):
# class String(VariablePrimitive):
# class Bytes(VariablePrimitive):
# class Array(Primitive):
#     def __init__(self, value):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __eq__(self, other):
#     def __repr__(self):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __repr__(self):
#     def of(cls, part_class):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __repr__(self):


import struct
import unittest
import zlib
import six
from kiel.protocol import primitives

    def test_string_render_parse_is_stable(self):
        s = primitives.String(u"foobar")

        fmt, values = s.render()

        raw = struct.pack("!" + fmt, *values)

        value, _ = primitives.String.parse(raw, 0)

        self.assertEqual(value, u"foobar")

    def test_string_render_parse_handles_nonstrings(self):
        s = primitives.String(123)

        fmt, values = s.render()

        raw = struct.pack("!" + fmt, *values)

        value, _ = primitives.String.parse(raw, 0)

        self.assertEqual(value, u"123")

    def test_bytes_render_parse_is_stable(self):
        b = primitives.Bytes(u"foobar")

        fmt, values = b.render()

        raw = struct.pack("!" + fmt, *values)


# Path: kiel/protocol/primitives.py
# class Primitive(object):
# class VariablePrimitive(Primitive):
# class Int8(Primitive):
# class Int16(Primitive):
# class Int32(Primitive):
# class Int64(Primitive):
# class String(VariablePrimitive):
# class Bytes(VariablePrimitive):
# class Array(Primitive):
#     def __init__(self, value):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __eq__(self, other):
#     def __repr__(self):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __repr__(self):
#     def of(cls, part_class):
#     def render(self):
#     def parse(cls, buff, offset):
#     def __repr__(self):


# Path: tests/protocol/test_primitives.py
import struct
import unittest
import zlib
import six
from kiel.protocol import primitives


    def test_string_render_parse_is_stable(self):
        s = primitives.String(u"foobar")

        fmt, values = s.render()

        raw = struct.pack("!" + fmt, *values)

        value, _ = primitives.String.parse(raw, 0)

        self.assertEqual(value, u"foobar")

    def test_string_render_parse_handles_nonstrings(self):
        s = primitives.String(123)

        fmt, values = s.render()

        raw = struct.pack("!" + fmt, *values)

        value, _ = primitives.String.parse(raw, 0)

        self.assertEqual(value, u"123")

    def test_bytes_render_parse_is_stable(self):
        b = primitives.Bytes(u"foobar")

        fmt, values = b.render()

        raw = struct.pack("!" + fmt, *values)


        value, _ = primitives.Bytes.parse(raw, 0)