Exemplo n.º 1
0
 def create(cls, from_unit, to_unit, factor):
     with scoped_session() as session:
         obj0 = cls(from_unit=from_unit, to_unit=to_unit, factor=factor)
         obj1 = cls(from_unit=to_unit, to_unit=from_unit, factor=1/factor)
         session.add(obj0)
         session.add(obj1)
     reconfigure_units()
Exemplo n.º 2
0
 def _getitem(cls, key):
     if isinstance(key, tuple):
         f = cls.aliases[key[0].lower()] if key[0].lower() in cls.aliases else key[0]
         t = cls.aliases[key[1].lower()] if key[1].lower() in cls.aliases else key[1]
         with scoped_session() as session:
             return session.query(cls).filter(and_(cls.from_unit==f, cls.to_unit==t)).one().factor
     else:
         raise KeyError('Usage requires syntax Dimension["from_unit", "to_unit"]')
Exemplo n.º 3
0
 def test_unit_creation(self):
     """Test :func:`~exa.cms.unit.Dimension.create`."""
     Length.create("xyz", "zyx", 1)
     self.assertEqual(unit.units[('xyz', 'zyx')], 1)
     self.assertEqual(unit.units[('zyx', 'xyz')], 1)
     with scoped_session() as session:
         session.query(Length).filter(Length.from_unit=="xyz").delete()
         session.query(Length).filter(Length.from_unit=="zyx").delete()
Exemplo n.º 4
0
 def get_by_symbol(cls, symbol):
     """Get the value of a constant with the given symbol."""
     if symbol.lower() in cls.aliases:
         symbol = cls.aliases[symbol.lower()]
     with scoped_session() as session:
         return session.query(cls).filter(cls.symbol == symbol).one().value
Exemplo n.º 5
0
def init_tutorial():
    """Create the tutorial notebook."""
    fp = os.path.join(config['paths']['notebooks'], 'tutorial.ipynb')
    with scoped_session() as session:
        tutorial = File.from_path(fp)
        session.add(tutorial)