<commit_before>#! /usr/bin/python

import unittest
from xbee import XBee

"""
test_xbee.py
By <NAME>, 2010

Tests the XBee superclass module for XBee API conformance.
"""

class TestChecksumming(unittest.TestCase):
    """
    XBee class must properly generate and verify checksums for binary
    data sent to and received from an XBee device
    """
    def test_checksum(self):
        """
        The checksum of binary data must be correct
        """
        # Simple start
        data = '\x00'
        chksum = XBee.checksum(data)
        self.assertEqual(chksum, 0xFF)
        
        # Once more
        data = '\x36'
        chksum = XBee.checksum(data)
        self.assertEqual(chksum, 0xc9)
        
        # Multi bytes
        data = '\x01\x01\x01\x01\x01'
        chksum = XBee.checksum(data)
        self.assertEqual(chksum, 0xFA)
        
    def test_verify_checksum(self):
        """
        verify_checksum must properly assert that the given data
        and checksum are correct
        """
        data = '\x00'
        chksum = '\xff'
        self.assertTrue(XBee.verify_checksum(data, chksum))
        
        data = '\x36'
        chksum = '\xc9'
        self.assertTrue(XBee.verify_checksum(data, chksum))
        
        data = '\x01\x01\x01\x01\x01'
        chksum = '\xFA'
        self.assertTrue(XBee.verify_checksum(data, chksum))

class TestAPIFrameGeneration(unittest.TestCase):
    """
    XBee class must be able to create a valid API frame given binary
    data, in byte string form.
    """
    pass
   
if __name__ == '__main__':
    unittest.main()
<commit_msg>Reorganized checksum tests into independent functions, factored out common data into setUp function<commit_after>#! /usr/bin/python

import unittest
from xbee import XBee

"""
test_xbee.py
By <NAME>, 2010

Tests the XBee superclass module for XBee API conformance.
"""

class TestChecksumming(unittest.TestCase):
    """
    XBee class must properly generate and verify checksums for binary
    data sent to and received from an XBee device
    """
    def setUp(self):
        self.data1 = '\x00'
        self.data2 = '\x36'
        self.data3 = '\x01\x01\x01\x01\x01'
        
    def test_checksum(self):
        """
        checksum a simple byte
        """
        chksum = XBee.checksum(self.data1)
        self.assertEqual(chksum, 0xFF)
        
    def test_checksum_again(self):
        """
        checksum a different byte
        """
        chksum = XBee.checksum(self.data2)
        self.assertEqual(chksum, 0xc9)
        
    def test_checksum_multibyte(self):
        """
        checksum more than one byte
        """
        chksum = XBee.checksum(self.data3)
        self.assertEqual(chksum, 0xFA)
        
    def test_verify_checksum(self):
        """
        verify_checksum a single byte
        """
        chksum = '\xff'
        self.assertTrue(XBee.verify_checksum(self.data1, chksum))
        
    def test_verify_checksum_again(self):
        """
        verify_checksum a different byte
        """
        chksum = '\xc9'
        self.assertTrue(XBee.verify_checksum(self.data2, chksum))
        
    def test_verify_checksum_multibyte(self):
        """
        verify_checksum multiple bytes
        """
        chksum = '\xFA'
        self.assertTrue(XBee.verify_checksum(self.data3, chksum))

class TestAPIFrameGeneration(unittest.TestCase):
    """
    XBee class must be able to create a valid API frame given binary
    data, in byte string form.
    """
    pass
   
if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.09769792251544077, 'fraction_numerical': 0.019371139809096015, 'mean_word_length': 2.1419753086419755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '6290586', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1154, 'n_words': 280}