Skip to content
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ install:

script:
- python unit-test/Spice/test_BasicElement.py
- python unit-test/Spice/test_HighLevelElement.py
9 changes: 7 additions & 2 deletions PySpice/Spice/HighLevelElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ class PieceWiseLinearMixin(SourceMixinAbc):
delay time time = td. The current source still needs to be patched, td and r are not yet
available.

`values` should be given as a list of (`Time`, `Value`)-tuples, e.g.::

PieceWiseLinearVoltageSource(Circuit(''), 'inpwl1', '1', '0',
values=[(0, 0), (10@u_ms, 0), (11@u_ms, 5@u_V), (20@u_ms, 5@u_V)])

"""

##############################################
Expand All @@ -361,7 +366,7 @@ def __init__(self, values, repeate_time=0, delay_time=.0):

# Fixme: default

self.values = [self.__as_unit__(x) for x in values]
self.values = sum(([as_s(t), self.__as_unit__(x)] for (t, x) in values), [])
self.repeate_time = as_s(repeate_time)
self.delay_time = as_s(delay_time)

Expand All @@ -371,7 +376,7 @@ def format_spice_parameters(self):

# Fixme: to func?
return ('PWL(' +
join_list(self.values) +
join_list(self.values) + ' ' +
join_dict({'r':self.repeate_time, 'td':self.delay_time}) + # OrderedDict(
')')

Expand Down
2 changes: 1 addition & 1 deletion PySpice/Tools/StringTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ def join_list(items):

def join_dict(d):
return ' '.join(["{}={}".format(key, str_spice(value))
for key, value in d.items()
for key, value in sorted(d.items())
if value is not None])
2 changes: 1 addition & 1 deletion setup_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
else:
pyspice_path = pyspice_path.parent
init_path = pyspice_path.joinpath('PySpice', '__init__.py')
with open(init_path) as fh:
with open(str(init_path)) as fh:
try:
version = re.findall(r"^__version__ = '([^']+)'\r?$", fh.read(), re.M)[0]
except IndexError:
Expand Down
53 changes: 53 additions & 0 deletions unit-test/Spice/test_HighLevelElement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
####################################################################################################
#
# PySpice - A Spice Package for Python
# Copyright (C) 2014 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################

####################################################################################################

import unittest

####################################################################################################

from PySpice.Spice.HighLevelElement import *
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *

####################################################################################################

class TestHighLevelElement(unittest.TestCase):

##############################################

def _test_spice_declaration(self, element, spice_declaration):

self.assertEqual(str(element), spice_declaration)

##############################################

def test(self):

self._test_spice_declaration(PieceWiseLinearVoltageSource(Circuit(''), 'inpwl1', '1', '0',
values=[(0, 0), (10@u_ms, 0), (11@u_ms, 5@u_V), (20@u_ms, 5@u_V)]),
'Vinpwl1 1 0 PWL(0s 0V 10ms 0V 11ms 5V 20ms 5V r=0s td=0.0s)')

####################################################################################################

if __name__ == '__main__':

unittest.main()