Skip to content

Commit 0a26ef4

Browse files
Merge pull request #27 from theme-ontology/bugfix-emptyingfield
Bugfix emptying entry
2 parents 6eedccb + e39aef7 commit 0a26ef4

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

tests/utils/test_mergelist.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def test_badrow_raises(self):
6363
rows[0].rtheme = ''
6464
with pytest.raises(ValueError):
6565
totolo.util.mergelist.get_changes(rows, totolo.empty())
66+
rows[0].theme = ''
67+
with pytest.raises(ValueError):
68+
totolo.util.mergelist.get_changes(rows, totolo.empty())
6669

6770
def test_badrow_action_raises(self):
6871
with pytest.raises(ValueError):

totolo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
The Python interface to themeontology.org.
33
"""
44

5-
__version__ = "1.7.3"
5+
__version__ = "1.8.0"
66

77
from totolo.api import TORemote, empty, files
88

totolo/impl/entry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __setitem__(self, key, value):
6262
field = TOField(
6363
name=key,
6464
fieldtype="blob",
65-
source=[data],
65+
source=[':: ' + self.name] + [data],
6666
parts=[data],
6767
)
6868
self.fields[key] = field.setup()

totolo/impl/field.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class TOField(TOObject):
1212
source = a(list)
1313
parts = a(list)
1414
frozen = a(False)
15+
__initialized = False
1516

1617
def __iadd__(self, other):
1718
assert isinstance(other, TOField)
@@ -144,8 +145,9 @@ def find_kw(self, match_keyword):
144145
return None
145146

146147
def setup(self):
147-
if not self.parts and not self.frozen:
148+
if not self.__initialized and not self.parts and not self.frozen:
148149
# this used to be done immediately but is now defered for efficiency
149150
from .parser import TOParser # pylint: disable=cyclic-import
150151
TOParser.init_field(self)
152+
self.__initialized = True
151153
return self

totolo/impl/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def make_field(cls, lines, fieldtype):
130130
@classmethod
131131
def init_field(cls, field):
132132
fieldtype = field.fieldtype
133+
field.parts.clear()
133134
if fieldtype == "kwlist":
134135
data_iter = islice(field.source, 1, 1000)
135136
for kwtuple in TOParser.iter_kwitems(data_iter):

totolo/util/mergelist.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ def get_changes(rows, ontology):
102102

103103
for row in rows:
104104
if not row.theme or not row.weight:
105-
newentries[row.sid][row.rweight].append([
106-
row.rtheme, row.rmotivation, row.rcapacity
107-
])
105+
if row.rtheme:
106+
newentries[row.sid][row.rweight].append([
107+
row.rtheme, row.rmotivation, row.rcapacity
108+
])
109+
else:
110+
raise ValueError(f"Unexpected row configuration (no theme/weight): {row}")
108111
elif not any([row.rtheme, row.rweight, row.rmotivation, row.rcapacity]):
109112
deletions[(row.sid, row.weight, row.theme)] = True
110113
elif row.rtheme and row.rweight:

0 commit comments

Comments
 (0)