""" Does get/set with different units convert correctly?
        """
        context = None
        meter_log = Log((1,2,3),units=meters)
        setitem_units = {'depth':inch}
        getitem_units = {'depth':feet}
        adapter = UnitConversionAdapter(getitem_units=getitem_units,
                                        setitem_units=setitem_units)
        name, inch_log = adapter.adapt_setitem(context, 'depth', meter_log)
        self.assert_(all(inch_log==meter_log.as_units(inch)))

        name, feet_log = adapter.adapt_getitem(context, 'depth', inch_log)
        # Did the values get converted correctly?
        self.assert_(all(feet_log==meter_log.as_units(feet)))

        # Are the units assigned correctly?
        self.assert_(feet_log.units==feet)

        return

################################################################################
# Test the doctests specified within the module.
################################################################################

from geo.context.adapter import unit_conversion_adapter
module_test = doctest_for_module(unit_conversion_adapter)


if __name__ == '__main__':
    unittest.main()
Beispiel #2
0
class AnalysisDocTestCase(doctest_for_module(analysis)):
    pass
Beispiel #3
0
class FunctionArgumentsDocTestCase(doctest_for_module(function_signature)):
    pass
class TreeDocTestCase(doctest_for_module(tree)):
    pass
class FunctionalDocTestCase(doctest_for_module(functional)):
    pass
Beispiel #6
0
class SequenceDocTestCase(doctest_for_module(sequence)):
    pass
Beispiel #7
0
        meter_log = UnitArray((1, 2, 3), units=meters)
        setitem_units = {'depth': inch}
        getitem_units = {'depth': feet}
        adapter = UnitConversionAdapter(getitem_units=getitem_units,
                                        setitem_units=setitem_units)
        name, inch_log = adapter.adapt_setitem(context, 'depth', meter_log)
        self.assertTrue(all(inch_log == meter_log.as_units(inch)))

        name, feet_log = adapter.adapt_getitem(context, 'depth', inch_log)
        # Did the values get converted correctly?
        self.assertTrue(all(feet_log == meter_log.as_units(feet)))

        # Are the units assigned correctly?
        self.assertTrue(feet_log.units == feet)

        return


################################################################################
# Test the doctests specified within the module.
################################################################################

# When nosetests is running this test module, it is not necessary to run
# doctests here also.  In fact, the code below causes nosetests to fail.
if 'nose' not in sys.modules:
    from codetools.contexts.adapter import unit_conversion_adapter
    module_test = doctest_for_module(unit_conversion_adapter)

if __name__ == '__main__':
    unittest.main()
Beispiel #8
0
class UnitScalarDocTestCase(doctest_for_module(unit_scalar)):
    pass
class DictDocTestCase(doctest_for_module(dict)):
    pass
class CompilerDocTestCase(doctest_for_module(compiler_)):
    pass
class GraphDocTestCase(doctest_for_module(G)):
    pass
class ParserDocTestCase(doctest_for_module(parser_)):
    pass
Beispiel #13
0
class SimpleMathTestCase(doctest_for_module(simple_math)):
    pass
Beispiel #14
0
class BlockDocTestCase(doctest_for_module(block)):
    pass