@@ -50,13 +50,19 @@ def test_device_slug(self):
5050 self .assertEqual (str (id ), 'd--0000-0000-0000-0001' )
5151 self .assertEqual (id .get_id (), 1 )
5252
53+ self .assertRaises (ValueError , IOTileDeviceSlug , 'string' )
54+ self .assertRaises (ValueError , IOTileDeviceSlug , 'x--0000-0000-0000-0001' )
55+ self .assertRaises (ValueError , IOTileDeviceSlug , '0000-0000-0000-0000' )
56+ self .assertRaises (ValueError , IOTileDeviceSlug , - 5 )
57+ self .assertRaises (ValueError , IOTileDeviceSlug , 0 )
58+
5359 def test_block_slug (self ):
5460 id = IOTileBlockSlug (5 )
5561 self .assertEqual (str (id ), 'b--0000-0000-0000-0005' )
5662 id = IOTileBlockSlug (0xa )
5763 self .assertEqual (str (id ), 'b--0000-0000-0000-000a' )
5864
59- self .assertRaises (AssertionError , IOTileBlockSlug , 'b--0000-0000-1234' )
65+ self .assertRaises (ValueError , IOTileBlockSlug , 'b--0000-0000-1234' )
6066
6167 id = IOTileBlockSlug ('b--0001-0000-0000-1234' )
6268 self .assertEqual (str (id ), 'b--0001-0000-0000-1234' )
@@ -74,13 +80,23 @@ def test_block_slug(self):
7480
7581 self .assertEqual (id .formatted_id (), '0003-0000-0000-0005' )
7682
83+ self .assertRaises (ValueError , IOTileBlockSlug , 'string' )
84+ self .assertRaises (ValueError , IOTileBlockSlug , 'x--0000-0000-0000-0001' )
85+ self .assertRaises (ValueError , IOTileBlockSlug , '0000-0000-0000-0000' )
86+ self .assertRaises (ValueError , IOTileBlockSlug , - 5 )
87+ self .assertRaises (ValueError , IOTileBlockSlug , 0 )
88+
7789 def test_variable_slug (self ):
78- self .assertRaises (AssertionError , IOTileVariableSlug , 5 )
90+ self .assertRaises (ValueError , IOTileVariableSlug , 'foo' )
7991
8092 id = IOTileVariableSlug (5 , '1234' )
8193 self .assertEqual (str (id ), 'v--0000-1234--0005' )
8294 self .assertEqual (id .formatted_local_id (), '0005' )
8395
96+ id = IOTileVariableSlug (5 )
97+ self .assertEqual (str (id ), 'v--0000-0000--0005' )
98+ self .assertEqual (id .formatted_local_id (), '0005' )
99+
84100 id = IOTileVariableSlug (5 , IOTileProjectSlug ('1234' ))
85101 self .assertEqual (str (id ), 'v--0000-1234--0005' )
86102 self .assertEqual (id .formatted_local_id (), '0005' )
@@ -91,9 +107,12 @@ def test_variable_slug(self):
91107 id = IOTileVariableSlug ('v--0000-1234--0005' )
92108 self .assertEqual (str (id ), 'v--0000-1234--0005' )
93109
110+ self .assertRaises (ValueError , IOTileVariableSlug , - 5 )
111+ self .assertRaises (ValueError , IOTileVariableSlug , 0 )
112+
94113 def test_stream_slug (self ):
95- self .assertRaises (AssertionError , IOTileStreamSlug , 5 )
96- self .assertRaises (AssertionError , IOTileStreamSlug , 's--0001' )
114+ self .assertRaises (ValueError , IOTileStreamSlug , 5 )
115+ self .assertRaises (ValueError , IOTileStreamSlug , 's--0001' )
97116
98117 id = IOTileStreamSlug ('s--0000-0001--0000-0000-0000-0002--0003' )
99118 self .assertEqual (str (id ), 's--0000-0001--0000-0000-0000-0002--0003' )
@@ -135,6 +154,22 @@ def test_stream_from_parts(self):
135154 id .from_parts (project = 7 , device = 1 , variable = vslug )
136155 self .assertEqual (str (id ), 's--0000-0007--0000-0000-0000-0001--5002' )
137156
157+ id = IOTileStreamSlug ()
158+ id .from_parts (project = 7 , device = 1 , variable = '5002' )
159+ self .assertEqual (str (id ), 's--0000-0007--0000-0000-0000-0001--5002' )
160+
161+ # Project is the only one that can be zero (wildcard)
162+ id = IOTileStreamSlug ()
163+ id .from_parts (project = 0 , device = 1 , variable = '5002' )
164+ self .assertEqual (str (id ), 's--0000-0000--0000-0000-0000-0001--5002' )
165+
166+ id = IOTileStreamSlug ()
167+ with pytest .raises (ValueError ):
168+ id .from_parts (project = - 1 , device = 1 , variable = '5002' )
169+ with pytest .raises (ValueError ):
170+ id .from_parts (project = 1 , device = - 1 , variable = '5002' )
171+ with pytest .raises (ValueError ):
172+ id .from_parts (project = 1 , device = 1 , variable = - 1 )
138173
139174 def test_id_property (self ):
140175 project = IOTileProjectSlug (5 )
@@ -145,32 +180,30 @@ def test_id_property(self):
145180
146181 id = IOTileStreamSlug ()
147182 id .from_parts (project = project , device = device , variable = variable )
148- self .assertRaises (AssertionError , id .get_id )
149-
150-
151- def test_streamer_gid ():
152- """Ensure that IOTileStreamerSlug works."""
183+ self .assertRaises (ValueError , id .get_id )
153184
154- s_gid = IOTileStreamerSlug (1 , 2 )
155- assert str (s_gid ) == "t--0000-0000-0000-0001--0002"
156- assert s_gid .get_device () == "d--0000-0000-0000-0001"
157- assert s_gid .get_index () == "0002"
185+ def test_streamer_gid (self ):
186+ """Ensure that IOTileStreamerSlug works."""
158187
159- s_gid = IOTileStreamerSlug ("d--0000-0000-0000-1234" , 1 )
160- assert str (s_gid ) == "t--0000-0000-0000-1234--0001"
188+ s_gid = IOTileStreamerSlug (1 , 2 )
189+ assert str (s_gid ) == "t--0000-0000-0000-0001--0002"
190+ assert s_gid .get_device () == "d--0000-0000-0000-0001"
191+ assert s_gid .get_index () == "0002"
161192
162- with pytest . raises ( ValueError ):
163- IOTileStreamerSlug ([], 1 )
193+ s_gid = IOTileStreamerSlug ( "d--0000-0000-0000-1234" , 1 )
194+ assert str ( s_gid ) == "t--0000-0000-0000-1234--0001"
164195
165- d_gid = IOTileDeviceSlug (15 )
166- s_gid = IOTileStreamerSlug (d_gid , 0 )
167- assert str (s_gid ) == "t--0000-0000-0000-000f--0000"
168- assert s_gid .get_device () == str (d_gid )
169- assert s_gid .get_index () == "0000"
196+ with pytest .raises (ValueError ):
197+ IOTileStreamerSlug ([], 1 )
170198
199+ d_gid = IOTileDeviceSlug (15 )
200+ s_gid = IOTileStreamerSlug (d_gid , 0 )
201+ assert str (s_gid ) == "t--0000-0000-0000-000f--0000"
202+ assert s_gid .get_device () == str (d_gid )
203+ assert s_gid .get_index () == "0000"
171204
172- def test_fleet_gid ():
173- """Ensure that IOTileFleetSlug works."""
205+ def test_fleet_gid (self ):
206+ """Ensure that IOTileFleetSlug works."""
174207
175- f_gid = IOTileFleetSlug (1 )
176- assert str (f_gid ) == 'g--0000-0000-0001'
208+ f_gid = IOTileFleetSlug (1 )
209+ assert str (f_gid ) == 'g--0000-0000-0001'
0 commit comments