<commit_before>from cubes.workspace import create_slicer_workspace
from cubes.errors import *
import cubes.browser

w = create_slicer_workspace("http://localhost:5010/")

cube_list = w.list_cubes()

def first_date_dim(cube):
    for d in cube.dimensions:
        if ( d.info.get('is_date') ):
            return d
    raise BrowserError("No date dimension in cube %s" % cube.name)

for c in cube_list:
    print ("Doing %s..." % c.get('name')),
    cube = w.cube(c.get('name'))
    date_dim = first_date_dim(cube)
    cut = cubes.browser.RangeCut(date_dim, [ 2013, 9, 25 ], None)
    cell = cubes.browser.Cell(cube, [ cut ])
    drill = cubes.browser.Drilldown([(date_dim, None, date_dim.level('day'))], cell)
    b = w.browser(cube)
    try:
        attr_dim = cube.dimension("attr")
        split = cubes.browser.PointCut(attr_dim, ['paid', 'pnb'])
    except:
        split = None
    try:
        result = b.aggregate(cell, drilldown=drill, split=split, measure=cube.measures[0])
        print result.cells
    except:
        import sys
        print sys.exc_info()
<commit_msg>Wrap the slicer test in unittest. Enable it by setting TEST_SLICER environment variable to anything.<commit_after>import unittest
import os

from cubes.workspace import create_slicer_workspace
from cubes.errors import *
import cubes.browser

@unittest.skipIf("TEST_SLICER" not in os.environ,
                 "No TEST_SLICER environment variable set.")

class SlicerTestCase(unittest.TestCase):
    def setUp(self):
        self.w = create_slicer_workspace("http://localhost:5010/")

        self.cube_list = self.w.list_cubes()

    def first_date_dim(self, cube):
        for d in cube.dimensions:
            if ( d.info.get('is_date') ):
                return d
        raise BrowserError("No date dimension in cube %s" % cube.name)

    def test_basic(self):
        for c in self.cube_list:
            print ("Doing %s..." % c.get('name')),
            cube = self.w.cube(c.get('name'))
            date_dim = self.first_date_dim(cube)
            cut = cubes.browser.RangeCut(date_dim, [ 2013, 9, 25 ], None)
            cell = cubes.browser.Cell(cube, [ cut ])
            drill = cubes.browser.Drilldown([(date_dim, None, date_dim.level('day'))], cell)
            b = w.browser(cube)
            try:
                attr_dim = cube.dimension("attr")
                split = cubes.browser.PointCut(attr_dim, ['paid', 'pnb'])
            except:
                split = None
            try:
                result = b.aggregate(cell, drilldown=drill, split=split, measure=cube.measures[0])
                print result.cells
            except:
                import sys
                print sys.exc_info()

{'fraction_non_alphanumeric': 0.1227810650887574, 'fraction_numerical': 0.008875739644970414, 'mean_word_length': 2.398241206030151, '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': '5283284', 'n_tokens_mistral': 927, 'n_tokens_neox': 862, 'n_words': 198}