-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
67 lines (50 loc) · 1.9 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import unittest
import struct
import stegapy.errors
from stegapy.parsers.WAV import WAV
import random
class TestContainerModel(unittest.TestCase):
def setUp(self):
from stegapy.models.container import BaseContainer as container
self.test_unit = container('test')
def test_init(self):
self.assertEqual(self.test_unit.name, 'test')
def test_write(self):
content = bytes(42)
self.test_unit.write(content)
with open('test', 'rb') as test_file:
_file = test_file.read()
self.assertEqual(_file, content)
def test_write_two(self):
content = 42
opcode = self.test_unit.write(content)
if opcode == 'OK':
with open('test', 'rb') as test_file:
_file = test_file.read()
self.assertEqual(_file, bytes(content))
class TestStegtoolModel(unittest.TestCase):
def setUp(self):
from stegapy.models.stega import BaseSteganography
self.stegtool = BaseSteganography
self.num = random.Random()
self.test_unit = self.stegtool(self.num)
def test_container_setter(self):
self.assertEqual(self.num, self.test_unit.container)
def test_abstract_encode(self):
self.assertEqual(None, self.test_unit.encode())
def test_abstract_decode(self):
self.assertEqual(None, self.test_unit.decode())
class TestRIFFWav(unittest.TestCase):
def setUp(self):
self.test_unit = WAV('test.wav')
def test_params_read(self):
_id = struct.unpack_from('>4s', self.test_unit.content[0:4])[0]
self.assertEqual(_id, self.test_unit.chunk_id)
def test_valid(self):
self.assertTrue(self.test_unit.is_valid())
class TestNotRIFFWav(unittest.TestCase):
def test_valid(self):
with self.assertRaises(stegapy.errors.ContainerError):
WAV('test_not_riff.wav')
if __name__ == '__main__':
unittest.main()