3 ms·
Here's that with Pint for Quantities and Units with `%pip install -q` for Jupyter notebooks with e.g. Google Colab or vscode.dev+pyodide or JupyterLite or ... i
by westurner 3y ago
Here's that with Pint for Quantities and Units with `%pip install -q` for Jupyter notebooks with e.g. Google Colab or vscode.dev+pyodide or JupyterLite or ... in Jupyter notebook Percent format with the %%ipytest cell magic function to upgrade test assertions (and @pytest.fixture s) and run everything starting with test_ with the pytest test runner:
# %%
%pip install -q pint ipytest pytest-cov
import ipytest
ipytest.autoconfig()
# %%
%%ipytest -v # --help
def test_pint_units_for_watt_meters():
import pint
ureg = pint.UnitRegistry()
unit1 = ureg.kilogram*(ureg.meter**2)*(ureg.seconds**-3)
unit2 = unit1 * ureg.meter
assert 1*unit1 == 1*ureg.watt
assert 1*unit2 == 1*ureg.watt*ureg.meters