<commit_before>import unittest
from testlib import testutil, PygrTestProgram
from pygr import cnestedlist, nlmsa_utils, seqdb, sequence

class NestedList_Test(unittest.TestCase):
    "Basic cnestedlist class tests"

    def setUp(self):
        self.db = cnestedlist.IntervalDB()
        ivals = [(0,10,1,-110,-100), (-20,-5,2,300,315)]
        self.db.save_tuples(ivals)

    def test_query(self):
        "NestedList query"
        assert self.db.find_overlap_list(0,10) == \
                         [(0, 10, 1, -110, -100), (5, 20, 2, -315, -300)]

    def test_reverse(self):
        "NestedList reverse"
        assert self.db.find_overlap_list(-11,-7) == \
                         [(-10, 0, 1, 100, 110), (-20, -5, 2, 300, 315)]

    def test_filedb(self):
        "NestedList filedb"
        tempdir  = testutil.TempDir('nlmsa-test')
        filename = tempdir.subfile('nlmsa')
        self.db.write_binaries(filename)
        fdb=cnestedlist.IntervalFileDB(filename)
        assert fdb.find_overlap_list(0,10) == \
                         [(0, 10, 1, -110, -100), (5, 20, 2, -315, -300)]
        assert fdb.find_overlap_list(-11,-7) == \
                         [(-10, 0, 1, 100, 110), (-20, -5, 2, 300, 315)]
        
        # fails on windows
        #tempdir.remove()  @CTB

class NLMSA_SimpleTests(unittest.TestCase):

    def setUp(self):
        pass

    def test_empty(self):
        "NLMSA Empty"
        blasthits  = testutil.tempdatafile('blasthits')

        msa = cnestedlist.NLMSA(blasthits , 'memory', pairwiseMode=True)
        try:
            msa.build()
            raise AssertionError('failed to trap empty alignment!')
        except nlmsa_utils.EmptyAlignmentError:
            pass

    def test_empty2(self):
        "NLMSA Empty 2"
        blasthits = testutil.tempdatafile('blasthits2')
        msa = cnestedlist.NLMSA(blasthits, mode='w', pairwiseMode=True)
        try:
            msa.build()
            raise AssertionError('failed to trap empty alignment!')
        except nlmsa_utils.EmptyAlignmentError:
            pass

    def test_build(self):
        "NLMSA build"
        
        testnlmsa = testutil.tempdatafile('testnlmsa')
        msa = cnestedlist.NLMSA(testnlmsa, mode='w', pairwiseMode=True,
                                bidirectional=False)
        # @CTB should there be something else here?  What is this testing?
<commit_msg>added test for bug 84<commit_after>import unittest
from testlib import testutil, PygrTestProgram
from pygr import cnestedlist, nlmsa_utils, seqdb, sequence

class NestedList_Test(unittest.TestCase):
    "Basic cnestedlist class tests"

    def setUp(self):
        self.db = cnestedlist.IntervalDB()
        ivals = [(0,10,1,-110,-100), (-20,-5,2,300,315)]
        self.db.save_tuples(ivals)

    def test_query(self):
        "NestedList query"
        assert self.db.find_overlap_list(0,10) == \
                         [(0, 10, 1, -110, -100), (5, 20, 2, -315, -300)]

    def test_reverse(self):
        "NestedList reverse"
        assert self.db.find_overlap_list(-11,-7) == \
                         [(-10, 0, 1, 100, 110), (-20, -5, 2, 300, 315)]

    def test_filedb(self):
        "NestedList filedb"
        tempdir  = testutil.TempDir('nlmsa-test')
        filename = tempdir.subfile('nlmsa')
        self.db.write_binaries(filename)
        fdb=cnestedlist.IntervalFileDB(filename)
        assert fdb.find_overlap_list(0,10) == \
                         [(0, 10, 1, -110, -100), (5, 20, 2, -315, -300)]
        assert fdb.find_overlap_list(-11,-7) == \
                         [(-10, 0, 1, 100, 110), (-20, -5, 2, 300, 315)]
        
        # fails on windows
        #tempdir.remove()  @CTB

class NLMSA_SimpleTests(unittest.TestCase):

    def setUp(self):
        pass

    def test_empty(self):
        "NLMSA Empty"
        blasthits  = testutil.tempdatafile('blasthits')

        msa = cnestedlist.NLMSA(blasthits , 'memory', pairwiseMode=True)
        try:
            msa.build()
            raise AssertionError('failed to trap empty alignment!')
        except nlmsa_utils.EmptyAlignmentError:
            pass

    def test_empty2(self):
        "NLMSA Empty 2"
        blasthits = testutil.tempdatafile('blasthits2')
        msa = cnestedlist.NLMSA(blasthits, mode='w', pairwiseMode=True)
        try:
            msa.build()
            raise AssertionError('failed to trap empty alignment!')
        except nlmsa_utils.EmptyAlignmentError:
            pass

    def test_build(self):
        "NLMSA build"
        
        testnlmsa = testutil.tempdatafile('testnlmsa')
        msa = cnestedlist.NLMSA(testnlmsa, mode='w', pairwiseMode=True,
                                bidirectional=False)
        # @CTB should there be something else here?  What is this testing?

    def test_lpo_query(self):
        s1=sequence.Sequence('aaaa','s1')
        s2=sequence.Sequence('bbbb','s2')
        msa = cnestedlist.NLMSA(mode='memory')
        msa[0:4]+=s1
        msa[0:4]+=s2
        msa.build()
        msaSlice = msa[0:4]
        assert len(msaSlice) == 2
        l = [t[0:2] for t in msaSlice.edges()]
        l.sort()
        correct = [(slice(0,4),s1),(slice(0,4),s2)]
        correct.sort()
        assert l == correct

{'fraction_non_alphanumeric': 0.12688131072585254, 'fraction_numerical': 0.04819965707753858, 'mean_word_length': 2.113879003558719, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3700127', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1735, 'n_words': 369}