From a41e74965038595b1b0b2d250e6740e349799cc2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 21 Dec 2024 00:19:04 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .gitignore | 2 +- python/units_python.cpp | 27 ++++++++++++++++++++------- test/python/test_conversion.py | 16 ++++++++-------- test/python/test_measurement.py | 32 ++++++++++++++++---------------- test/python/test_units.py | 14 +++++++------- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index fb526bca..5e3809b5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ build *.pyd *.egg-info .vscode -.vs \ No newline at end of file +.vs diff --git a/python/units_python.cpp b/python/units_python.cpp index 9184e979..92a4bc5c 100644 --- a/python/units_python.cpp +++ b/python/units_python.cpp @@ -51,12 +51,15 @@ NB_MODULE(units_llnl_ext, mod) "set_commodity", [](units::precise_unit* unit, const char* commodity) { return units::precise_unit( - unit->multiplier(),unit->base_units(), units::getCommodity(std::string(commodity))); + unit->multiplier(), + unit->base_units(), + units::getCommodity(std::string(commodity))); }) .def( "set_multiplier", [](units::precise_unit* unit, double mult) { - return units::precise_unit(mult, unit->base_units(),unit->commodity()); + return units::precise_unit( + mult, unit->base_units(), unit->commodity()); }) .def("inv", &units::precise_unit::inv) .def(nb::self * nb::self) @@ -194,11 +197,18 @@ NB_MODULE(units_llnl_ext, mod) return units::precise_measurement(value, measurement->units()); }) .def("units", &units::precise_measurement::units) - .def("set_units", [](units::precise_measurement* measurement, const units::precise_unit& unit) { - return units::precise_measurement(measurement->value(), unit); + .def( + "set_units", + [](units::precise_measurement* measurement, + const units::precise_unit& unit) { + return units::precise_measurement(measurement->value(), unit); }) - .def("set_units", [](units::precise_measurement* measurement, const char *unit) { - return units::precise_measurement(measurement->value(),units::unit_from_string(std::string(unit))); + .def( + "set_units", + [](units::precise_measurement* measurement, const char* unit) { + return units::precise_measurement( + measurement->value(), + units::unit_from_string(std::string(unit))); }) .def( "value_as", @@ -226,7 +236,10 @@ NB_MODULE(units_llnl_ext, mod) return measurement.convert_to( units::unit_from_string(std::string(units))); }) - .def("convert_to_base", &units::precise_measurement::convert_to_base,"convert a measurement to a measurement using the base si units") + .def( + "convert_to_base", + &units::precise_measurement::convert_to_base, + "convert a measurement to a measurement using the base si units") .def("as_unit", &units::precise_measurement::as_unit) .def(nb::self * nb::self) .def(nb::self / nb::self) diff --git a/test/python/test_conversion.py b/test/python/test_conversion.py index f797be32..26c89ecc 100644 --- a/test/python/test_conversion.py +++ b/test/python/test_conversion.py @@ -10,29 +10,29 @@ def test_convert_units(): u2=u.unit('cm') v1=u.convert(10,u1,u2) assert(v1==10*100) - + v2=u.convert(unit_in=u1,unit_out=u2,value=20) assert(v2==2000) - + def test_convert_string(): v1=u.convert(10,'m','mm') assert(v1==10*1000) - + v2=u.convert(unit_out='mm',unit_in='m',value=20) assert(v2==20000) - + def test_convert_units_pu(): u1=u.unit('puMW') u2=u.unit('kW') v1=u.convert_pu(0.5,u1,u2,100) assert(v1==50000) - + v2=u.convert_pu(unit_in=u1,unit_out=u2,value=1.2,base=100) assert(v2==120000) - + def test_convert_string_pu(): v1=u.convert_pu(0.5,'puMW','kW',100) assert(v1==50000) - + v2=u.convert_pu(unit_in='puMW',unit_out='kW',value=1.2,base=100) - assert(v2==120000) \ No newline at end of file + assert(v2==120000) diff --git a/test/python/test_measurement.py b/test/python/test_measurement.py index d11f4256..7dc80958 100644 --- a/test/python/test_measurement.py +++ b/test/python/test_measurement.py @@ -75,19 +75,19 @@ def test_set_value(): assert(m1.value()==100) m2=m1.set_value(14) assert(m2.value()==14) - + def test_set_units(): m1=u.measurement('100 months') assert(m1.units()==u.unit('month')) m2=m1.set_units(u.unit('day')) assert(m2.units()==u.unit('day')) - + def test_value_as(): m1=u.measurement('20 weeks') assert(m1.value_as('day')==20*7) u1=u.unit('hr') assert(m1.value_as(u1)==20*7*24) - + def test_convert_to(): m1=u.measurement('20 weeks') m2=m1.convert_to('day') @@ -95,54 +95,54 @@ def test_convert_to(): u1=u.unit('hr') m3=m1.convert_to('hr') assert(m3.value()==20*7*24) - + m4=m1.convert_to_base() assert(m4.units()==u.unit('s')) assert(m4.units().multiplier()==1.0) assert(m4.value()==20*7*24*3600) - + def test_as_unit(): m1=u.measurement('15 seconds') m2=u.measurement(4,m1.as_unit()) - + assert(m2.value()==4) assert(m2.value_as('s')==60) - + def test_add_sub(): m1=u.measurement('15 seconds') m2=u.measurement(1,'minute') m3=m2-m1 assert(m3.value()==0.75) - + m4=m3+m2+m1 assert(m4==u.measurement(120,'second')) - + def test_mult(): m1=u.measurement('2 meters') m2=u.measurement(3,'meters') m3=m2*m1 assert(m3.value()==6) - + m4=3*m3 assert(m4==u.measurement(18,'meters squared')) - + m5=m3*3 assert(m5==u.measurement(18,'meters squared')) - + def test_div(): m1=u.measurement('10 meters') m2=u.measurement(2,'seconds') m3=m1/m2 assert(m3.value()==5) - + m4=10/m3 assert(m4==u.measurement(2,'s/m')) - + m5=m3/2.5 assert(m5==u.measurement(2,'m/s')) - + def test_string(): m1=u.measurement('10 lb') assert(m1.to_string()=='10 lb') s3=f"the measurement is {m1}" - assert(s3=="the measurement is 10 lb") \ No newline at end of file + assert(s3=="the measurement is 10 lb") diff --git a/test/python/test_units.py b/test/python/test_units.py index 1f30f9ee..5eabb621 100644 --- a/test/python/test_units.py +++ b/test/python/test_units.py @@ -36,7 +36,7 @@ def test_conditions(): assert(u3.is_valid()) assert(not u3.is_finite()) assert(u3.isinf()) - + def test_root(): u1=u.unit('m^6 per second squared') u2=u1.root(2) @@ -44,7 +44,7 @@ def test_root(): u4=u.unit('m*m*m/s') assert(u2==u3) assert(u3==u4) - + def test_base(): u1=u.unit('3 ft') u2 = u.unit('yd') @@ -53,7 +53,7 @@ def test_base(): assert(u1==u2) assert(u1.has_same_base(u2)) assert(u2.has_same_base(u3)) - + def test_multiplier(): u1=u.unit('nm') assert(u1.multiplier()==1e-9) @@ -68,25 +68,25 @@ def test_commodity(): assert(u1.commodity()=='gold') u2 = u1.set_commodity('silver') assert(u2.commodity()=='silver') - + def test_string(): u1=u.unit('lb') assert(u1.to_string()=='lb') s3=f"the unit is {u1}" assert(s3=="the unit is lb") - + def test_inv(): u1=u.unit('s') assert(u1.inv()==u.unit('Hz')) u3=u1.inv().inv() assert(u3==u1) - + def test_float_mult(): u1=u.unit('m') m3=10*u1 assert(type(m3).__name__=='measurement') assert(m3.value()==10) - + m4=u1*12 assert(type(m4).__name__=='measurement') assert(m4.value()==12)