-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c6d1ee
commit 41afb18
Showing
2 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
import marshal | ||
import json | ||
|
||
from .. import TestUnitBase | ||
|
||
|
||
class TestPyMarshal(TestUnitBase): | ||
|
||
def test_integer(self): | ||
unit = self.load() | ||
data = 935532112 | ||
test = marshal.dumps(data) | unit | bytes | ||
self.assertEqual(int.from_bytes(test, 'big'), data) | ||
|
||
def test_string(self): | ||
unit = self.load() | ||
data = 'The binary refinery refines the finest binaries.' | ||
test = marshal.dumps(data) | unit | str | ||
self.assertEqual(test, data) | ||
|
||
def test_strings(self): | ||
unit = self.load() | ||
data = 'The binary refinery refines the finest binaries.'.split() | ||
test = marshal.dumps(data) | unit | [str] | ||
self.assertEqual(test, data) | ||
|
||
def test_json(self): | ||
unit = self.load() | ||
data = { | ||
'foo': None, | ||
'bar': [1, 12, 7], | ||
'baz': { | ||
'x': 'refined', | ||
'y': 'binaries', | ||
} | ||
} | ||
test = marshal.dumps(data) | unit | json.loads | ||
self.assertEqual(test, data) | ||
|
||
def test_bytes(self): | ||
unit = self.load() | ||
for k in (1, 2, 12, 200, 353444): | ||
t = self.generate_random_buffer(k) | ||
self.assertEqual(marshal.dumps(t) | unit | bytes, t) | ||
|
||
def test_code(self): | ||
def test_function(): | ||
print('refine your binaries!') | ||
|
||
from refinery.units.formats.pyc import pyc | ||
from refinery.units.formats.pym import pym | ||
|
||
data = marshal.dumps(test_function.__code__) | ||
test = data | pym | pyc | str | ||
self.assertIn('refine your binaries!', test) |