Skip to content

Commit

Permalink
Merge pull request PauloRadatz#48 from eniovianna/master
Browse files Browse the repository at this point in the history
Minor refactor
  • Loading branch information
PauloRadatz authored Jul 21, 2022
2 parents 234dc1c + e7b790a commit 4736b8e
Show file tree
Hide file tree
Showing 23 changed files with 262 additions and 249 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def read(*names, **kwargs):
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Utilities',
Expand Down
4 changes: 1 addition & 3 deletions src/py_dss_interface/models/Lines/LinesF.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import ctypes

from py_dss_interface.models.Base import Base
from py_dss_interface.models.Lines import LinesS
from py_dss_interface.models.Text.Text import Text


class LinesF(Base):
Expand Down Expand Up @@ -105,7 +103,7 @@ def lines_write_emerg_amps(self, argument: float) -> float:
return float(self.dss_obj.LinesF(ctypes.c_int32(17), ctypes.c_double(argument)))

def lines_read_rg(self) -> float:
"""Gets the earth return value used to compute line impedances at power frequency."""
"""Gets the earth return value used to compute line impedance's at power frequency."""
return float(self.dss_obj.LinesF(ctypes.c_int32(18), ctypes.c_double(0)))

def lines_write_rg(self, argument: float) -> float:
Expand Down
13 changes: 7 additions & 6 deletions tests/py_dss_interface/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
# @File : conftest.py
# @Software: PyCharm

import pytest
import pathlib
import os
import pathlib

import pytest

import py_dss_interface
import time

script_path = os.path.dirname(os.path.abspath(__file__))


@pytest.fixture(scope='function')
def solve_snap_13bus():
dss = py_dss_interface.DSSDLL(r"C:\OpenDSS")
dss = py_dss_interface.DSSDLL()
actual = dss.started
expected = True
# expected = True

message = f"OpenDSSDirectDLL has been loaded: {actual}"
# message = f"OpenDSSDirectDLL has been loaded: {actual}"

# assert actual is expected, message

Expand Down
2 changes: 1 addition & 1 deletion tests/py_dss_interface/test_activeclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_active_class_get_name(self, dss):

def test_active_class_write_name(self, dss):
expected = '645646'
actual = dss.active_class_write_name(expected)
dss.active_class_write_name(expected)
actual = dss.active_class_get_name()
assert actual == expected

Expand Down
2 changes: 1 addition & 1 deletion tests/py_dss_interface/test_cktelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_cktelement_energymeter(self, dss):
def test_cktelement_controller(self, dss):
# https://github.com/PauloRadatz/py_dss_interface/issues/2 - Issue solved =)
dss.text("New 'Fuse.f1' MonitoredObj=Line.650632 MonitoredTerm=1 FuseCurve=Klink RatedCurrent=65")
# After include a new element it become the active element. So, we need activate another element to test the
# After include a new element it becomes the active element. So, we need activate another element to test the
# methods below
dss.circuit_set_active_element('Line.650632')
expected = "Fuse.f1"
Expand Down
3 changes: 2 additions & 1 deletion tests/py_dss_interface/test_cmathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_cmathlib_cabs(self, dss):
assert actual == expected

def test_cmathlib_cdang(self, dss):
real, imag = 1, 1
expected = 45
actual = dss.cmathlib_cdang(1, 1)
assert actual == expected
Expand All @@ -50,3 +49,5 @@ def test_cmathlib_pdegtocomplex(self, dss):
real, imag = 3.1622776601683795, 1.2490457723982544
actual = dss.cmathlib_pdegtocomplex(real, imag)
expected = complex(real, imag)
assert actual == expected

9 changes: 6 additions & 3 deletions tests/py_dss_interface/test_dssinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
# @Software: PyCharm


import pytest
import os
import pathlib

import pytest


class TestDSSInterface13Bus:

Expand Down Expand Up @@ -84,14 +85,16 @@ def test_dss_write_allow_forms(self, dss):
def test_dss_read_datapath(self, dss):
expected = r"C:\\PauloRadatz\\GitHub\\py-dss-interface\\tests\\py_dss_interface\\cases\\13Bus\\"
actual = dss.dss_read_datapath()
assert actual.replace("\\", "").split("py-dss-interfacetests")[1] == expected.replace("\\", "").split("py-dss-interfacetests")[1]
assert actual.replace("\\", "").split("py-dss-interfacetests")[1] == \
expected.replace("\\", "").split("py-dss-interfacetests")[1]

def test_dss_write_datapath(self, dss):
data_path = str(pathlib.Path(os.path.dirname(__file__)).joinpath("cases", "13Bus", "datapath"))
dss.dss_write_datapath(data_path)
expected = data_path
actual = dss.dss_read_datapath()
assert actual.replace("\\", "").split("py-dss-interfacetests")[1] == expected.replace("\\", "").split("py-dss-interfacetests")[1]
assert actual.replace("\\", "").split("py-dss-interfacetests")[1] == \
expected.replace("\\", "").split("py-dss-interfacetests")[1]

def test_dss_default_editor(self, dss):
expected = 'Notepad.exe'
Expand Down
3 changes: 2 additions & 1 deletion tests/py_dss_interface/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def dss(self, solve_snap_13bus):

return dss

def include_generator(self, dss):
@staticmethod
def include_generator(dss):
dss.text(
'New Generator.G2 Bus1=645.1 phases=1 kV=2.4 kW=100 Model=3 Vpu=1 Maxkvar=500 Minkvar=-400'
)
Expand Down
41 changes: 21 additions & 20 deletions tests/py_dss_interface/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ def test_lines_read_geometry(self, dss):
def test_lines_write_geometry(self, dss):

dss.text(
"New WireData.1/0_ACSR Rac=0.646847 Runits=km GMRac=0.13589 GMRUnits=cm Radius=0.50546 Radunits=cm Normamps=260 Emergamps=260")
"New WireData.1/0_ACSR Rac=0.646847 Runits=km GMRac=0.13589 GMRUnits=cm Radius=0.50546 Radunits=cm "
"Normamps=260 Emergamps=260")
dss.text("New LineGeometry.1PH-x4_ACSRx4_ACSR nconds=2 nphases=1 "
" cond=1 wire=1/0_ACSR x=-0.1524 h=10.5156 units=m "
" cond=2 wire=1/0_ACSR x=0.1524 h=8.2296 units=m "
" reduce=y ")
" cond=1 wire=1/0_ACSR x=-0.1524 h=10.5156 units=m "
" cond=2 wire=1/0_ACSR x=0.1524 h=8.2296 units=m "
" reduce=y ")

expected = '1PH-x4_ACSRx4_ACSR'.lower()
dss.lines_write_geometry(expected)
Expand Down Expand Up @@ -163,10 +164,10 @@ def test_lines_write_length(self, dss):
def test_lines_read_r1(self, dss):

dss.text("New linecode.Sequences nphases=3 "
"r1=0.3489 x1=0.426198 r0=0.588811 x0=1.29612 "
"c1=10.4308823411236 c0=4.48501282215346 "
"units=km baseFreq=60 normamps=310 emergamps=310 "
"faultrate=0.1 pctperm=20 repair=3")
"r1=0.3489 x1=0.426198 r0=0.588811 x0=1.29612 "
"c1=10.4308823411236 c0=4.48501282215346 "
"units=km baseFreq=60 normamps=310 emergamps=310 "
"faultrate=0.1 pctperm=20 repair=3")

dss.text("New line.MyLine linecode=Sequences length=1")
dss.lines_write_name('MyLine')
Expand All @@ -177,10 +178,10 @@ def test_lines_read_r1(self, dss):

def test_lines_write_r1(self, dss):
dss.text("New linecode.Sequences nphases=3 "
"r1=0.3489 x1=0.426198 r0=0.588811 x0=1.29612 "
"c1=10.4308823411236 c0=4.48501282215346 "
"units=km baseFreq=60 normamps=310 emergamps=310 "
"faultrate=0.1 pctperm=20 repair=3")
"r1=0.3489 x1=0.426198 r0=0.588811 x0=1.29612 "
"c1=10.4308823411236 c0=4.48501282215346 "
"units=km baseFreq=60 normamps=310 emergamps=310 "
"faultrate=0.1 pctperm=20 repair=3")

dss.text("New line.MyLine linecode=Sequences length=1")
dss.lines_write_name('MyLine')
Expand All @@ -192,10 +193,10 @@ def test_lines_write_r1(self, dss):

def test_lines_read_x1(self, dss):
dss.text("New linecode.Sequences nphases=3 "
"r1=0.3489 x1=0.426198 r0=0.588811 x0=1.29612 "
"c1=10.4308823411236 c0=4.48501282215346 "
"units=km baseFreq=60 normamps=310 emergamps=310 "
"faultrate=0.1 pctperm=20 repair=3")
"r1=0.3489 x1=0.426198 r0=0.588811 x0=1.29612 "
"c1=10.4308823411236 c0=4.48501282215346 "
"units=km baseFreq=60 normamps=310 emergamps=310 "
"faultrate=0.1 pctperm=20 repair=3")

dss.text("New line.MyLine linecode=Sequences length=1")
dss.lines_write_name('MyLine')
Expand All @@ -206,10 +207,10 @@ def test_lines_read_x1(self, dss):

def test_lines_write_x1(self, dss):
dss.text("New linecode.Sequences nphases=3 "
"r1=0.3489 x1=0.426198 r0=0.588811 x0=1.29612 "
"c1=10.4308823411236 c0=4.48501282215346 "
"units=km baseFreq=60 normamps=310 emergamps=310 "
"faultrate=0.1 pctperm=20 repair=3")
"r1=0.3489 x1=0.426198 r0=0.588811 x0=1.29612 "
"c1=10.4308823411236 c0=4.48501282215346 "
"units=km baseFreq=60 normamps=310 emergamps=310 "
"faultrate=0.1 pctperm=20 repair=3")

dss.text("New line.MyLine linecode=Sequences length=1")
dss.lines_write_name('MyLine')
Expand Down
41 changes: 21 additions & 20 deletions tests/py_dss_interface/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# @File : test_load.py
# @Software: PyCharm

import pytest
import platform

import pytest


class TestLoad13Bus:

Expand Down Expand Up @@ -123,11 +124,11 @@ def test_loads_read_cvr_curve(self, dss):

def test_loads_write_cvr_curve(self, dss):
dss.text("New Loadshape.Test npts=24 interval=1 "
"mult= "
"(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 "
"0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 "
"1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 "
"0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
"mult= "
"(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 "
"0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 "
"1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 "
"0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
expected = 'Test'
dss.loads_write_cvr_curve(expected)
actual = dss.loads_read_cvr_curve()
Expand All @@ -140,11 +141,11 @@ def test_loads_read_daily(self, dss):

def test_loads_write_daily(self, dss):
dss.text("New Loadshape.Test npts=24 interval=1 "
"mult= "
"(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 "
"0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 "
"1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 "
"0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
"mult= "
"(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 "
"0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 "
"1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 "
"0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
expected = 'Test'
dss.loads_write_daily(expected)
actual = dss.loads_read_daily()
Expand All @@ -162,10 +163,10 @@ def test_loads_read_spectrum(self, dss):

def test_loads_write_spectrum(self, dss):
dss.text("New Spectrum.Test "
"NumHarm=7 "
"harmonic=(1, 3, 5, 7, 9, 11, 13, ) "
"%mag=(100, 1.5, 20, 14, 1, 9, 7, ) "
"angle=(0, 180, 180, 180, 180, 180, 180, )")
"NumHarm=7 "
"harmonic=(1, 3, 5, 7, 9, 11, 13, ) "
"%mag=(100, 1.5, 20, 14, 1, 9, 7, ) "
"angle=(0, 180, 180, 180, 180, 180, 180, )")
expected = 'Test'
dss.loads_write_spectrum(expected)
actual = dss.loads_read_spectrum()
Expand All @@ -178,11 +179,11 @@ def test_loads_read_yearly(self, dss):

def test_loads_write_yearly(self, dss):
dss.text("New Loadshape.Test npts=24 interval=1 "
"mult= "
"(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 "
"0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 "
"1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 "
"0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
"mult= "
"(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 "
"0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 "
"1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 "
"0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
expected = 'Test'
dss.loads_write_yearly(expected)
actual = dss.loads_read_yearly()
Expand Down
13 changes: 7 additions & 6 deletions tests/py_dss_interface/test_loadshapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ def dss(self, solve_snap_13bus):

return dss

def new_loadshape(self, dss, activate: bool = False):
@staticmethod
def new_loadshape(dss, activate: bool = False):
dss.text("New Loadshape.Test npts=24 interval=1 Pbase=100 Qbase=50 "
"mult= "
"(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 "
"0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 "
"1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 "
"0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
"mult= "
"(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 "
"0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 "
"1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 "
"0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
if activate:
dss.loadshapes_write_name('test')

Expand Down
7 changes: 5 additions & 2 deletions tests/py_dss_interface/test_monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class TestMonitors13Bus:
def dss(self, solve_snap_13bus):
dss = solve_snap_13bus
dss.text(
"New Loadshape.1 npts=24 interval=1 mult=(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 0.41000000 0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 1.45000005 1.62000000 1.88999999 1.79999995 1.78999996 1.19000006 0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 0.23000000)")
"New Loadshape.1 npts=24 interval=1 mult=(0.18000001 0.19000000 0.23999999 0.33000001 0.38999999 "
"0.41000000 0.64999998 1.23000002 1.88999999 1.88999999 1.96000004 1.98000002 1.45000005 1.62000000 "
"1.88999999 1.79999995 1.78999996 1.19000006 0.80000001 0.66000003 0.51999998 0.40000001 0.28000000 "
"0.23000000)")
dss.loads_write_daily("1")
dss.text("New monitor.m1 element=Transformer.XFM1 terminal=1 mode=0")
dss.text(f"Set DataPath={path}")
Expand Down Expand Up @@ -91,7 +94,7 @@ def test_monitors_process_all(self, dss):
assert actual == expected

def test_monitors_file_version(self, dss):
# TODO: file_version returns diferent values each time
# TODO: file_version returns different values each time
expected = 0
actual = dss.monitors_file_version()
assert type(actual) == type(expected)
Expand Down
2 changes: 1 addition & 1 deletion tests/py_dss_interface/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def dss(self, solve_snap_13bus):
def test_parallel_num_cpus(self, dss):
expected = 4
actual = dss.parallel_num_cpus()
#assert actual == expected
# assert actual == expected

def test_parallel_num_cores(self, dss):
expected = 2
Expand Down
Loading

0 comments on commit 4736b8e

Please sign in to comment.