Skip to content

Commit 6cd1274

Browse files
committed
Consolidate usage of random module
1 parent 157414a commit 6cd1274

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

test/bdd/steps/place_inserter.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ def add_row(self, row, force_name):
2828
assert 'osm_type' in self.columns, "osm column missing"
2929

3030
if force_name and 'name' not in self.columns:
31-
self._add_hstore('name', 'name',
32-
''.join(random.choice(string.printable)
33-
for _ in range(int(random.random()*30))))
31+
self._add_hstore(
32+
"name",
33+
"name",
34+
"".join(random.choices(string.printable, k=random.randrange(30))),
35+
)
3436

3537
return self
3638

@@ -104,7 +106,7 @@ def db_insert(self, cursor):
104106
if self.columns['osm_type'] == 'N' and self.geometry is None:
105107
pt = self.context.osm.grid_node(self.columns['osm_id'])
106108
if pt is None:
107-
pt = (random.random()*360 - 180, random.random()*180 - 90)
109+
pt = (random.uniform(-180, 180), random.uniform(-90, 90))
108110

109111
self.geometry = "ST_SetSRID(ST_Point(%f, %f), 4326)" % pt
110112
else:

test/bdd/steps/steps_osm_data.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def write_opl_file(opl, grid):
4141
if line.startswith('n') and line.find(' x') < 0:
4242
coord = grid.grid_node(int(line[1:].split(' ')[0]))
4343
if coord is None:
44-
coord = (random.random() * 360 - 180,
45-
random.random() * 180 - 90)
44+
coord = (random.uniform(-180, 180), random.uniform(-90, 90))
4645
line += " x%f y%f" % coord
4746
fd.write(line.encode('utf-8'))
4847
fd.write(b'\n')

0 commit comments

Comments
 (0)