Ejemplo n.º 1
0
    def test_dataFrame(self, dataFrame):
        datasearch = DataSearch("Test")
        assert datasearch.dataFrame().empty
        assert isinstance(datasearch.dataFrame(), pandas.DataFrame)

        datasearch = DataSearch("Test", dataFrame=dataFrame)
        assert len(datasearch.dataFrame()) == 3
Ejemplo n.º 2
0
    def test_indexSearch(self, dataFrame):
        datasearch = DataSearch('Test', dataFrame=dataFrame)

        filterString = 'indexSearch([0])'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 1

        filterString = 'indexSearch([0, 2])'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 2

        filterString = 'indexSearch([0, 1, 2])'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 3

        filterString = 'indexSearch([99])'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 0
Ejemplo n.º 3
0
 def test_filter_unknown_keyword(self, model, index):
     filterString = '(Foo < 10) and (Bar > 1)'
     search = DataSearch("Test", filterString)
     preFilterRows = model.rowCount()
     model.setFilter(search)
     postFilterRows = model.rowCount()
     assert preFilterRows == postFilterRows
Ejemplo n.º 4
0
    def test_extentSearch(self, geoDataFrame, dataFrame):
        datasearch = DataSearch('Test', dataFrame=geoDataFrame)

        filterString = 'extentSearch(51, 9, 55, 14)'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 1

        datasearch = DataSearch('Test', dataFrame=dataFrame)

        filterString = 'extentSearch(51, 9, 55, 14)'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 0
Ejemplo n.º 5
0
    def test_init(self, dataFrame):
        filterString = 'Foo < 10'
        datasearch = DataSearch("Test", filterString)
        assert datasearch._filterString == filterString
        assert isinstance(datasearch._dataFrame, pandas.DataFrame)
        assert datasearch.name == 'Test'

        datasearch = DataSearch("Test2")
        assert datasearch._filterString == ''
        assert isinstance(datasearch._dataFrame, pandas.DataFrame)
        assert datasearch.name == 'Test2'

        datasearch = DataSearch("Test3", dataFrame=dataFrame)
        assert datasearch._filterString == ''
        assert isinstance(datasearch._dataFrame, pandas.DataFrame)
        assert datasearch.name == 'Test3'
        assert len(datasearch._dataFrame.index) == 3
Ejemplo n.º 6
0
    def test_filter_multiColumn(self, model, index):
        filterString = '(Foo < 10) & (Bar > 1)'
        search = DataSearch("Test", filterString)
        preFilterRows = model.rowCount()
        model.setFilter(search)
        postFilterRows = model.rowCount()

        assert preFilterRows > postFilterRows
        assert preFilterRows == (postFilterRows + 2)
Ejemplo n.º 7
0
    def test_filter_freeSearch(self, model, index):
        filterString = 'freeSearch("10")'
        search = DataSearch("Test", filterString)
        preFilterRows = model.rowCount()
        model.setFilter(search)
        postFilterRows = model.rowCount()

        assert preFilterRows > postFilterRows
        assert preFilterRows == (postFilterRows + 2)
Ejemplo n.º 8
0
    def test_filter_single_column(self, model, index):
        filterString = 'Foo < 10'
        search = DataSearch("Test", filterString)
        preFilterRows = model.rowCount()
        model.setFilter(search)
        postFilterRows = model.rowCount()

        assert preFilterRows > postFilterRows
        assert preFilterRows == (postFilterRows + 1)
Ejemplo n.º 9
0
    def test_setFilterString(self):
        datasearch = DataSearch("Test")
        filterString = 'foo bar'
        datasearch.setFilterString(filterString)
        assert datasearch.filterString() == filterString

        filterString = ' foo bar '
        datasearch.setFilterString(filterString)
        assert datasearch.filterString() != filterString
        assert datasearch.filterString() == filterString.strip()
Ejemplo n.º 10
0
    def test_freeSearch(self, dataFrame):
        datasearch = DataSearch('Test', dataFrame=dataFrame)

        filterString = 'freeSearch("0")'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 2

        filterString = 'freeSearch(1)'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert not valid

        filterString = 'freeSearch("12")'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 1
Ejemplo n.º 11
0
    def __init__(self, dataFrame=None, copyDataFrame=False):
        """the __init__ method.

        Args:
            dataFrame (pandas.core.frame.DataFrame, optional): initializes the model with given DataFrame.
                If none is given an empty DataFrame will be set. defaults to None.
            copyDataFrame (bool, optional): create a copy of dataFrame or use it as is. defaults to False.
                If you use it as is, you can change it from outside otherwise you have to reset the dataFrame
                after external changes.

        """
        super(DataFrameModel, self).__init__()

        self._dataFrame = pandas.DataFrame()
        if dataFrame is not None:
            self.setDataFrame(dataFrame, copyDataFrame=copyDataFrame)

        self._dataFrameOriginal = None
        self._search = DataSearch("nothing", "")
        self.editable = False
Ejemplo n.º 12
0
    def test_search(self, dataFrame):
        datasearch = DataSearch('Test', dataFrame=dataFrame)

        filterString = 'Foo < 10'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 2

        filterString = 'Foo < 10 and Bar'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert not valid

        filterString = '(Foo < 10) & (Bar > 1)'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert valid
        assert sum(ret) == 1

        filterString = '(Monty < 10) & (Bar > 1)'
        datasearch.setFilterString(filterString)
        ret, valid = datasearch.search()
        assert not valid
Ejemplo n.º 13
0
 def setFilter(self):
     #filterIndex = eval(self.lineEditFilterCondition.text())
     search = DataSearch("Test", self.lineEditFilterCondition.text())
     self.dataTableView.view().model().setFilter(search)
Ejemplo n.º 14
0
 def test_filterString(self):
     datasearch = DataSearch("Test")
     assert datasearch.filterString() == ''
     datasearch = DataSearch('Test2', filterString='Hello World')
     assert datasearch.filterString() == 'Hello World'
Ejemplo n.º 15
0
 def test_repr(self, dataFrame):
     datasearch = DataSearch("Test2")
     assert str(datasearch).startswith('DataSearch(')
     assert str(datasearch).endswith('Test2 ()')