Factor out BoolFacet from StarredFacet and add BlankFacet.

This commit is contained in:
Paul Makepeace 2011-04-26 01:04:30 -04:00
parent b34ff146c4
commit b33d280ee7
2 changed files with 21 additions and 10 deletions

View File

@ -81,22 +81,34 @@ class TextFacet(Facet):
return self
class StarredFacet(TextFacet):
def __init__(self, selection=None):
class BoolFacet(TextFacet):
def __init__(self, column, expression=None, selection=None):
if selection is not None and not isinstance(selection, bool):
raise ValueError('selection must be True or False.')
if expression is None:
raise ValueError('Missing expression')
super(BoolFacet, self).__init__(column,
expression=expression, selection=selection)
class StarredFacet(BoolFacet):
def __init__(self, selection=None):
super(StarredFacet, self).__init__('',
expression='row.starred', selection=selection)
class FlaggedFacet(TextFacet):
class FlaggedFacet(BoolFacet):
def __init__(self, selection=None):
if selection is not None and not isinstance(selection, bool):
raise ValueError('selection must be True or False.')
super(FlaggedFacet, self).__init__('',
expression='row.flagged', selection=selection)
class BlankFacet(BoolFacet):
def __init__(self, column, selection=None):
super(BlankFacet, self).__init__(column,
expression='isBlank(value)', selection=selection)
# Capitalize 'From' to get around python's reserved word.
class NumericFacet(Facet):
def __init__(self, column, From=None, to=None, select_blank=True, select_error=True, select_non_numeric=True, select_numeric=True, **options):

View File

@ -11,7 +11,8 @@ import sys
import os
import unittest
from google.refine import REFINE_HOST, REFINE_PORT
from google.refine import NumericFacet, TextFacet, StarredFacet, Engine
from google.refine import NumericFacet, TextFacet
from google.refine import BlankFacet, StarredFacet, Engine
from google.refine import RefineServer, Refine, RefineProject
from google.refine import to_camel, from_camel
@ -300,8 +301,7 @@ class TutorialTestDuplicateDetection(RefineTestCase):
emails = [1 if r['email'] else 0 for r in response.rows]
self.assertEqual(emails, [1, 0, 1, 1, 1, 0, 0, 1, 1, 0])
# {12}
blank_facet = TextFacet('email', expression='isBlank(value)',
selection=True)
blank_facet = BlankFacet('email', selection=True)
# {13}
response = self.project.remove_rows(blank_facet)
self.assertTrue('Remove 4 rows' in
@ -467,8 +467,7 @@ class TutorialTestTransposeVariableNumbeOfRowsIntoColumns(RefineTestCase):
# {26}
self.project.engine.mode = 'row-based'
# {27}
blank_facet = TextFacet('First Line', expression='isBlank(value)',
selection=True)
blank_facet = BlankFacet('First Line', selection=True)
response = self.project.remove_rows(blank_facet)
self.assertEqual('Remove 14 rows',
response['historyEntry']['description'])