<commit_before><commit_msg>Add file for running gui filtering tests.<commit_after>  
"""
Slow tests for filtering systems
   
"""
import os
import tempfile
import shutil

import numpy as np

from . import base
from ..gui import mainWindow
from ..system.lattice import Lattice


def path_to_file(path):
    return os.path.join(os.path.dirname(__file__), "..", "..", "testing", path)


class TestFilteringKennyLattice(base.UsesQApplication):
    """
    Test filtering a system
       
    """
    def setUp(self):
        """
        Set up the test
        
        """
        super(TestFilteringKennyLattice, self).setUp()
        
        # tmp dir
        self.tmpLocation = tempfile.mkdtemp(prefix="atomanTest")
        
        # main window
        self.mw = mainWindow.MainWindow(None, testing=True)
        self.mw.preferences.renderingForm.maxAtomsAutoRun = 0
        self.mw.show()
        
        # copy a lattice to tmpLocation
        self.fn = os.path.join(self.tmpLocation, "testLattice.dat")
        shutil.copy(path_to_file("kenny_lattice.dat"), self.fn)
        
        # load Lattice
        try:
            self.mw.systemsDialog.load_system_form.readerForm.openFile(self.fn)
            state = self.mw.mainToolbar.pipelineList[0].inputState
            err = False
            if not isinstance(state, Lattice):
                err = True
            elif state.NAtoms != 1140:
                err = True
            if err:
                self.fail("Loading Lattice failed")
        except:
            self.fail("Loading Lattice failed")
    
    def tearDown(self):
        """
        Tidy up
        
        """
        super(TestFilteringKennyLattice, self).tearDown()
        
        # remove refs
        self.fn = None
        self.mw.close()
        self.mw = None
        
        # remove tmp dir
        shutil.rmtree(self.tmpLocation)
    
    def test_filterAtomID(self):
        """
        GUI: filter atom ID
           
        """
        # add the atom ID filter
        pp = self.mw.mainToolbar.pipelineList[0]
        flist = pp.filterLists[0]
        flist.addFilter(filterName="Atom ID")
        item = flist.listItems.item(0)
        item.filterSettings.lineEdit.setText("104,1,4-7")
        item.filterSettings.lineEdit.editingFinished.emit()
        
        # run the filter
        pp.runAllFilterLists()
        
        # check the result
        flt = flist.filterer
        atomids = (104, 1, 4, 5, 6, 7)
        self.assertEqual(len(flt.visibleAtoms), 6)
        for i in xrange(6):
            self.assertTrue(pp.inputState.atomID[flt.visibleAtoms[i]] in atomids)

{'fraction_non_alphanumeric': 0.10235920852359208, 'fraction_numerical': 0.009512937595129375, 'mean_word_length': 1.8238453276047262, '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': '4208670', 'n_tokens_mistral': 820, 'n_tokens_neox': 785, 'n_words': 166}