File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 1
1
"""Prototype for extracting and showing metadata (AMORE project)"""
2
2
3
- __version__ = '0.1.1 '
3
+ __version__ = '0.1.2 '
4
4
5
5
from .api import Damnit , RunVariables , VariableData
Original file line number Diff line number Diff line change @@ -237,8 +237,20 @@ def keys(self) -> list:
237
237
def _var_titles (self ):
238
238
result = self ._db .conn .execute ("SELECT name, title FROM variables" ).fetchall ()
239
239
available_vars = self .keys ()
240
- return { row [0 ]: row [1 ] if row [1 ] is not None else row [0 ] for row in result
241
- if row [0 ] in available_vars }
240
+ titles = { row [0 ]: row [1 ] if row [1 ] is not None else row [0 ] for row in result
241
+ if row [0 ] in available_vars }
242
+
243
+ # These variables are created automatically, but they aren't included in
244
+ # the `variables` table (yet) so we need to explicitly add their titles.
245
+ special_vars = {
246
+ "start_time" : "Timestamp" ,
247
+ "comment" : "Comment"
248
+ }
249
+ for name , title in special_vars .items ():
250
+ if name in available_vars :
251
+ titles [name ] = title
252
+
253
+ return titles
242
254
243
255
def titles (self ) -> list :
244
256
"""The titles of available variables.
Original file line number Diff line number Diff line change @@ -67,6 +67,19 @@ def test_run_variables(mock_db_with_data, monkeypatch):
67
67
assert rv ["scalar1" ].name == "scalar1"
68
68
assert rv ["Scalar1" ].name == "scalar1"
69
69
70
+ # Test getting the start_time. This one's a bit special because we create it
71
+ # automatically, it's a proper variable except for the fact that we don't
72
+ # insert it into the `variables` table.
73
+ assert isinstance (rv ["start_time" ].read (), float )
74
+ assert "Timestamp" in rv .titles ()
75
+
76
+ # Test getting comments. This is also special because it doesn't appear in
77
+ # the `variables` table.
78
+ assert "comment" not in rv .keys ()
79
+ db .change_run_comment (damnit .proposal , 1 , "foo" )
80
+ assert "Comment" in rv .titles ()
81
+ assert rv ["comment" ].read () == "foo"
82
+
70
83
with pytest .raises (KeyError ):
71
84
rv ["foo" ]
72
85
You can’t perform that action at this time.
0 commit comments