File: test_packet_writer.py

package info (click to toggle)
python-stetl 1.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 89,988 kB
  • sloc: python: 5,007; xml: 707; sql: 430; makefile: 155; sh: 50
file content (49 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download
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
import os

from stetl.etl import ETL
from stetl.filters.packetwriter import PacketWriter
from tests.stetl_test_case import StetlTestCase

class PacketWriterTest(StetlTestCase):
    """Unit tests for PacketWriter"""

    def setUp(self):
        super(PacketWriterTest, self).setUp()

        # Initialize Stetl
        curr_dir = os.path.dirname(os.path.realpath(__file__))
        cfg_dict = {'config_file': os.path.join(curr_dir, 'configs/packetwriter.cfg')}
        self.etl = ETL(cfg_dict)
    
    def test_class(self):
        chain = StetlTestCase.get_chain(self.etl)
        section = StetlTestCase.get_section(chain, 1)
        class_name = self.etl.configdict.get(section, 'class')
        
        self.assertEqual('filters.packetwriter.PacketWriter', class_name)
    
    def test_instance(self):
        chain = StetlTestCase.get_chain(self.etl)

        self.assertTrue(isinstance(chain.get_by_index(1), PacketWriter))
        
    def test_execute(self):
        chain = StetlTestCase.get_chain(self.etl)
        chain.run()

        # Check if temp file exists
        section = StetlTestCase.get_section(chain, 1)
        file_path = self.etl.configdict.get(section, 'file_path')
        self.assertTrue(os.path.exists(file_path))
        
        # Compare temp file to input file byte by byte
        section = StetlTestCase.get_section(chain)
        orig_file_path = self.etl.configdict.get(section, 'file_path')
        with open(file_path, 'rb') as f:
            file = f.read()
        with open(orig_file_path, 'rb') as f:
            orig_file = f.read()
        self.assertEqual(file, orig_file)
        
        # Remove temp file
        os.remove(file_path)