def context_factory(self):
     """ Return the type of context we are testing.
     """
     data_context=DataContext()
     context = AdaptedDataContext(context=data_context)
     name = self.key_name()
     getitem_units = {name:meters/second}
     adapter = UnitConversionAdapter(getitem_units=getitem_units)
     context.push_adapter(adapter)
     return context
Ejemplo n.º 2
0
    def setUp(self):

        unittest.TestCase.setUp(self)

        # Set up data for the contexts
        depth = linspace(0.0, 100.0, 11)
        lith = array(['sand'] * len(depth), dtype=object)

        # Create the contexts
        self.context = AdaptedDataContext(context=DataContext())
        self.raw_context = self.context.context

        # Add data (before creating the adapter)
        self.context.update(depth=depth, lith=lith)

        # Add an adapter
        self.mask = (20.0 <= depth) & (depth <= 50.0)
        self.adapter = MaskingAdapter(mask=self.mask)
        self.context.push_adapter(self.adapter)
Ejemplo n.º 3
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        # Put unit adapters on either side of a masking adapter to see if they
        # cooperate. Store meters in the raw context, push fathoms through the
        # mask, and expose feet to the outside world.
        self.units = units = { 'in':meters, 'mid':fathom, 'out':feet }

        # Set up data for the contexts
        depth = Log(linspace(0.0, 100.0, 11), units=units['in'])
        lith = array(['sand']*len(depth), dtype=object)

        # Create the contexts
        self.context = AdaptedDataContext(context=DataContext())
        self.raw_context = self.context.context

        # Add data (before creating the adapters)
        self.context.update(depth=depth, lith=lith)

        # (This simplifies creating UnitConversionAdapters)
        def always(value):
            class C(dict):
                def get(self, key, default=None):
                    return value
                def __repr__(self):
                    return '{*:%r}' % value
            return C()

        # Layer multiple adapters
        self.mask = (15.0 < depth) & (depth < 55.0)
        self.convert_out = lambda x: convert(x, units['in'], units['out'])
        self.convert_in = lambda x: convert(x, units['out'], units['in'])
        #self.context.push_adapter(
        #    UnitConversionAdapter(setitem_units=always(units['in']),
        #                          getitem_units=always(units['mid'])))
        self.context.push_adapter(MaskingAdapter(mask=self.mask))
        self.context.push_adapter(
        #    UnitConversionAdapter(setitem_units=always(units['mid']),
            UnitConversionAdapter(setitem_units=always(units['in']),
                                  getitem_units=always(units['out'])))
 def setUp(self):
     self.context = AdaptedDataContext(context=DataContext())