# Path: habitat/utils/filtertools.py
# class UKHASChecksumFixer(object):
#     def __init__(self, protocol, data):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def fix(cls, protocol, old_data, new_data):
#     def _sum(cls, protocol, data):
#     def _sum_length(cls, protocol):
#     def _split_str(cls, protocol, data):


from ...utils import filtertools
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with habitat.  If not, see <http://www.gnu.org/licenses/>.



class TestUKHASChecksumFixer:
    """UKHAS Checksum Fixer"""
    def test_leaves_bad_data(self):
        self.check_fixer("crc16-ccitt", "$$habitat,bad*ABCD\n",
            "$$habitat,good*ABCD\n", "$$habitat,bad*ABCD\n")

    def test_updates_checksum(self):
        self.check_fixer("crc16-ccitt", "$$habitat,good*4918\n",
            "$$habitat,other*4918\n", "$$habitat,other*2E0C\n")

    def test_updates_xor_checksum(self):
        self.check_fixer("xor", "$$habitat,good*4c\n",
            "$$habitat,other*4c\n", "$$habitat,other*2B\n")

    def test_leaves_when_protocol_is_none(self):
        self.check_fixer("none", "$$habitat,boring\n",
            "$$habitat,sucky\n", "$$habitat,sucky\n")

    def check_fixer(self, protocol, old, new, expect):
        data = {"data": old}
        with filtertools.UKHASChecksumFixer(protocol, data) as c:
            c["data"] = new
        assert c["data"] == expect

# Path: habitat/utils/filtertools.py
# class UKHASChecksumFixer(object):
#     def __init__(self, protocol, data):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def fix(cls, protocol, old_data, new_data):
#     def _sum(cls, protocol, data):
#     def _sum_length(cls, protocol):
#     def _split_str(cls, protocol, data):


# Path: habitat/tests/test_utils/test_filtertools.py
from ...utils import filtertools

# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with habitat.  If not, see <http://www.gnu.org/licenses/>.



class TestUKHASChecksumFixer:
    """UKHAS Checksum Fixer"""
    def test_leaves_bad_data(self):
        self.check_fixer("crc16-ccitt", "$$habitat,bad*ABCD\n",
            "$$habitat,good*ABCD\n", "$$habitat,bad*ABCD\n")

    def test_updates_checksum(self):
        self.check_fixer("crc16-ccitt", "$$habitat,good*4918\n",
            "$$habitat,other*4918\n", "$$habitat,other*2E0C\n")

    def test_updates_xor_checksum(self):
        self.check_fixer("xor", "$$habitat,good*4c\n",
            "$$habitat,other*4c\n", "$$habitat,other*2B\n")

    def test_leaves_when_protocol_is_none(self):
        self.check_fixer("none", "$$habitat,boring\n",
            "$$habitat,sucky\n", "$$habitat,sucky\n")

    def check_fixer(self, protocol, old, new, expect):
        data = {"data": old}
        with filtertools.UKHASChecksumFixer(protocol, data) as c:
            c["data"] = new
        assert c["data"] == expect

        assert filtertools.UKHASChecksumFixer.fix(protocol, old, new) == expect