Skip to content

Commit

Permalink
Version 5.0.0 - Going live
Browse files Browse the repository at this point in the history
- Migrated from internal repo
- Adding Unittests for fun! :D
- Debugging odd unit-test results
  • Loading branch information
CCP-Zeulix committed Apr 15, 2024
1 parent ba81d9e commit 1fe9dbb
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions tests/test_castutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
import shutil
import time

from sandbox.test import rainbow_pb2
from sandbox.test import rainbow_dc
from sandbox.test import enums_pb2
from sandbox.test import enums_dc

import logging
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
Expand Down Expand Up @@ -91,6 +86,8 @@ def test_big_kwdict(self):
message_map__mickey__foo='mouse'))

def test_mkproto(self):
from sandbox.test import rainbow_pb2

p1 = rainbow_pb2.SubMessage()
p1.foo = 'Foo!'
p1.bar = 'Bar!!!'
Expand All @@ -109,6 +106,8 @@ def test_mkproto(self):
self.assertEqual(p4, protoplasm.casting.mkproto(rainbow_pb2.SubMessage))

def test_nested_mkproto(self):
from sandbox.test import rainbow_pb2

p1 = rainbow_pb2.RainbowMessage()
self.assertEqual(p1, protoplasm.casting.mkproto(rainbow_pb2.RainbowMessage))

Expand Down Expand Up @@ -289,6 +288,8 @@ def test_nested_mkproto(self):
message_map__mickey__foo='mouse'))

def test_mkdataclass(self):
from sandbox.test import rainbow_dc

dc1 = rainbow_dc.SubMessage()
dc1.foo = 'Foo!'
dc1.bar = 'Bar!!!'
Expand All @@ -307,6 +308,8 @@ def test_mkdataclass(self):
self.assertEqual(dc4, protoplasm.casting.mkdataclass(rainbow_dc.SubMessage))

def test_nested_mkdataclass(self):
from sandbox.test import rainbow_dc

dc1 = rainbow_dc.RainbowMessage()
self.assertEqual(dc1, protoplasm.casting.mkdataclass(rainbow_dc.RainbowMessage))

Expand Down Expand Up @@ -483,6 +486,9 @@ def test_nested_mkdataclass(self):
))

def test_import_dataclass(self):
from sandbox.test import rainbow_pb2
from sandbox.test import rainbow_dc

self.assertEqual(rainbow_dc.SubMessage, castutils.import_dataclass_by_proto(rainbow_pb2.SubMessage))
self.assertEqual(rainbow_dc.SubMessage, castutils.import_dataclass_by_proto(rainbow_pb2.SubMessage()))
self.assertEqual(rainbow_dc.RainbowMessage, castutils.import_dataclass_by_proto(rainbow_pb2.RainbowMessage))
Expand All @@ -492,6 +498,8 @@ def test_import_dataclass(self):
self.assertNotEqual(castutils.import_dataclass_by_proto(rainbow_pb2.SubMessage), castutils.import_dataclass_by_proto(rainbow_pb2.RainbowMessage))

def test_timestamp_mkproto(self):
from sandbox.test import rainbow_pb2

ts1 = '2012-07-03T14:50:51.654321Z'
dt1 = datetime.datetime(2012, 7, 3, 14, 50, 51, 654321)
self.assertEqual(ts1, dt1.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
Expand Down Expand Up @@ -525,6 +533,8 @@ def test_timestamp_mkproto(self):
my_timestamp_map__midnight=ts5))

def test_timestamp_mkdataclass(self):
from sandbox.test import rainbow_dc

ts1 = '2012-07-03T14:50:51.654321Z'
dt1 = datetime.datetime(2012, 7, 3, 14, 50, 51, 654321)
self.assertEqual(ts1, dt1.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
Expand Down Expand Up @@ -559,6 +569,8 @@ def test_timestamp_mkdataclass(self):
my_timestamp_map__midnight=dt5))

def test_byte_mkproto(self):
from sandbox.test import rainbow_pb2

as_str_1 = 'Þórður Matthíasson'
as_bytes_1 = as_str_1.encode('utf-8')
as_base64_1 = base64.encodebytes(as_bytes_1).decode('utf-8').strip()
Expand Down Expand Up @@ -593,6 +605,8 @@ def test_byte_mkproto(self):
my_bytes_map__one=as_base64_5))

def test_byte_mkdataclass(self):
from sandbox.test import rainbow_dc

as_str_1 = 'Þórður Matthíasson'
as_bytes_1 = as_str_1.encode('utf-8')
as_base64_1 = base64.encodebytes(as_bytes_1).decode('utf-8').strip()
Expand Down Expand Up @@ -627,6 +641,8 @@ def test_byte_mkdataclass(self):
my_bytes_map__one=as_base64_5))

def test_enum_mkproto(self):
from sandbox.test import enums_pb2

p_expect = enums_pb2.WithExternalEnum()
p_expect.my_enum = enums_pb2.TWO

Expand Down Expand Up @@ -712,6 +728,8 @@ def test_enum_mkproto(self):
my_internal_alias_enum_map__default=0))

def test_enum_mkdataclass(self):
from sandbox.test import enums_dc

dc_expect = enums_dc.WithExternalEnum()
dc_expect.my_enum = enums_dc.TWO

Expand Down

0 comments on commit 1fe9dbb

Please sign in to comment.