Skip to content

Commit

Permalink
utils: disallow empty strings as series names
Browse files Browse the repository at this point in the history
  • Loading branch information
RobAtticus committed Mar 14, 2016
1 parent a952e37 commit 754e9d2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
9 changes: 3 additions & 6 deletions iobeam/resources/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def asMilliseconds(self):
elif self._type == TimeUnit.MILLISECONDS:
return self._value
elif self._type == TimeUnit.SECONDS:
return (self._value * 1000)
return self._value * 1000

def asMicroseconds(self):
"""This timestamp value represented in microseconds.
Expand Down Expand Up @@ -137,8 +137,6 @@ def toDict(self):
class DataStore(object):
"""A collection of data streams with rows batched by time."""

_RESERVED_NAMES = ["time", "time_offset", "all"]

def __init__(self, columns):
"""Construct a new DataStore object with given columns.
Expand All @@ -153,9 +151,8 @@ def __init__(self, columns):
raise ValueError("columns cannot be None or empty")
if not isinstance(columns, list):
raise ValueError("columns must be a list of strings")
for name in DataStore._RESERVED_NAMES:
if name in [c.lower() for c in columns]:
raise ValueError("'{}' is a reserved column name".format(name))
for c in columns:
utils.checkValidSeriesName(c)

self._columns = list(columns) # defensive copy
self._rows = []
Expand Down
18 changes: 18 additions & 0 deletions iobeam/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ def __checkNon0LengthString(value, valueName):
elif len(value) == 0:
raise ValueError("{} must be more than 0 characters".format(valueName))

__RESERVED_COL_NAMES = ["time", "time_offset", "all"]

def checkValidSeriesName(name):
"""Check that a series name is valid.
A valid series name is not reserved by iobeam (time, time_offset, all) and
a non-0 length string.
Raises:
ValueError - If `name` is (a) None, (b) not a string/unicode, (c)
is of length 0, or (d) reserved.
"""
__checkNon0LengthString(name, "columns")
if name.lower() in __RESERVED_COL_NAMES:
raise ValueError("'{}' is a reserved column name".format(name))

def checkValidDeviceId(deviceId):
"""Check that a deviceId is valid: string of len > 0
Expand All @@ -92,6 +108,8 @@ def checkValidProjectToken(token):
__LOGGER = None

def getLogger():
"""Get the logger for this library."""

global __LOGGER
if __LOGGER is not None:
logger = __LOGGER
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ required-attributes=
bad-functions=map,filter,input

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_,r,p,d,f,pt
good-names=i,j,k,ex,Run,_,r,p,d,f,pt,ts,c

# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
Expand Down
3 changes: 2 additions & 1 deletion tests/resources/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def verify(fields):
["time_offset", "col"],
["col", "TIME_OFfset"],
["all"],
["AlL"]
["AlL"],
["fine", ""]
]
for c in cases:
verify(c)
Expand Down

0 comments on commit 754e9d2

Please sign in to comment.