<commit_before>import py8583
from py8583 import Iso8583, MemDump, DT, LT
from py8583spec import IsoSpec1987BCD, IsoSpec1987ASCII
import binascii
import unittest

class AsciiParse1987(unittest.TestCase):
    
    def setUp(self):
        self.IsoPacket = Iso8583(IsoSpec = IsoSpec1987ASCII())
        self.IsoPacket.Strict(True)
    
    def tearDown(self):
        pass
    
    def test_MTI(self):
        # positive test
        for b1 in range(0, 9):
            for b2 in range(1, 9):
                for b3 in range(0,9):
                    for b4 in range(0, 5):
                        MTI = str(b1) + str(b2) + str(b3) + str(b4)
                        self.IsoPacket.SetIsoContent(MTI + "0000000000000000")
                        self.assertEqual(self.IsoPacket.MTI(), MTI)
    
        # negative test
        with self.assertRaisesRegexp(py8583.ParseError, "Invalid MTI"):
            self.IsoPacket.SetIsoContent("000A")
            
        with self.assertRaisesRegexp(py8583.ParseError, "Invalid MTI"):
            self.IsoPacket.SetIsoContent("0000")
            
        for b4 in range(6, 9):
            with self.assertRaisesRegexp(py8583.ParseError, "Invalid MTI"):
                MTI = "010" + str(b4)
                self.IsoPacket.SetIsoContent(MTI)
                
    def test_Bitmap(self):
        
        # Primary bitmap
        for shift in range(0, 63):
            bitmap = '{:0>16X}'.format(1 << shift)
            content = '0200' +  bitmap + ''.zfill(256)

            self.IsoPacket.SetIsoContent(content)
            self.assertEqual(self.IsoPacket.Bitmap()[64 - shift], 1)
            self.assertEqual(self.IsoPacket.Field(64 - shift), 1)
            
        # Secondary bitmap
        for shift in range(0, 64):
            bitmap = '8{:0>31X}'.format(1 << shift)
            content = '0200' +  bitmap + ''.zfill(256)
            
            self.IsoPacket.SetIsoContent(content)
            self.assertEqual(self.IsoPacket.Bitmap()[128 - shift], 1)
            self.assertEqual(self.IsoPacket.Field(128 - shift), 1)
                
class BCDParse1987(unittest.TestCase):
    
    def setUp(self):
        self.IsoPacket = Iso8583(IsoSpec = IsoSpec1987BCD())
        self.IsoPacket.Strict(True)
    
    def tearDown(self):
        pass
    
    def test_MTI(self):
        # positive test
        for b1 in range(0, 9):
            for b2 in range(1, 9):
                for b3 in range(0,9):
                    for b4 in range(0, 5):                        
                        MTI = str(b1) + str(b2) + str(b3) + str(b4)
                        self.IsoPacket.SetIsoContent(binascii.unhexlify(MTI + "0000000000000000"))
                        self.assertEqual(self.IsoPacket.MTI(), MTI)
                        
        # negative test<commit_msg>tests are python 3 compatible<commit_after>import py8583
from py8583 import Iso8583, MemDump, DT, LT
from py8583spec import IsoSpec1987BCD, IsoSpec1987ASCII
import binascii
import unittest

class AsciiParse1987(unittest.TestCase):
    
    def setUp(self):
        self.IsoPacket = Iso8583(IsoSpec = IsoSpec1987ASCII())
        self.IsoPacket.Strict(True)
    
    def tearDown(self):
        pass
    
    def test_MTI(self):
        # positive test
        for b1 in range(0, 9):
            for b2 in range(1, 9):
                for b3 in range(0,9):
                    for b4 in range(0, 5):
                        MTI = str(b1) + str(b2) + str(b3) + str(b4)
                        self.IsoPacket.SetIsoContent((MTI + "0000000000000000").encode('latin'))
                        self.assertEqual(self.IsoPacket.MTI(), MTI)
    
        # negative test
        with self.assertRaisesRegexp(py8583.ParseError, "Invalid MTI"):
            self.IsoPacket.SetIsoContent("000A".encode('latin'))
            
        with self.assertRaisesRegexp(py8583.ParseError, "Invalid MTI"):
            self.IsoPacket.SetIsoContent("0000".encode('latin'))
            
        for b4 in range(6, 9):
            with self.assertRaisesRegexp(py8583.ParseError, "Invalid MTI"):
                MTI = "010" + str(b4)
                self.IsoPacket.SetIsoContent(MTI.encode('latin'))
                
    def test_Bitmap(self):
        
        # Primary bitmap
        for shift in range(0, 63):
            bitmap = '{:0>16X}'.format(1 << shift)
            content = '0200' +  bitmap + ''.zfill(256)

            self.IsoPacket.SetIsoContent(content.encode('latin'))
            self.assertEqual(self.IsoPacket.Bitmap()[64 - shift], 1)
            self.assertEqual(self.IsoPacket.Field(64 - shift), 1)
            
        # Secondary bitmap
        for shift in range(0, 64):
            bitmap = '8{:0>31X}'.format(1 << shift)
            content = '0200' +  bitmap + ''.zfill(256)
            
            self.IsoPacket.SetIsoContent(content.encode('latin'))
            self.assertEqual(self.IsoPacket.Bitmap()[128 - shift], 1)
            self.assertEqual(self.IsoPacket.Field(128 - shift), 1)
                
class BCDParse1987(unittest.TestCase):
    
    def setUp(self):
        self.IsoPacket = Iso8583(IsoSpec = IsoSpec1987BCD())
        self.IsoPacket.Strict(True)
    
    def tearDown(self):
        pass
    
    def test_MTI(self):
        # positive test
        for b1 in range(0, 9):
            for b2 in range(1, 9):
                for b3 in range(0,9):
                    for b4 in range(0, 5):                        
                        MTI = str(b1) + str(b2) + str(b3) + str(b4)
                        self.IsoPacket.SetIsoContent(binascii.unhexlify(MTI + "0000000000000000"))
                        self.assertEqual(self.IsoPacket.MTI(), MTI)
                        
        # negative test
{'fraction_non_alphanumeric': 0.11149947570779448, 'fraction_numerical': 0.0634393568682279, 'mean_word_length': 1.6957136128120585, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1295231', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1782, 'n_words': 353}