class test_graph(): def setup(self): self.london_location = [51.5073509,-0.1277583] self.oxford_location = [51.7520209,-1.2577263] self.start = 'London' self.end = 'Oxford' self.mygraph = Greengraph(self.start,self.end) self.mygraph.geocoder.geocode = MagicMock(side_effect=side_effect) self.test_location_result = [[51.5073509,-0.1277583],[51.5685184,-0.4102503],[51.6296859,-0.6927423],[51.6908534,-0.9752343],[51.7520209,-1.2577263]] raw_data_location = path.join(path.dirname(__file__), 'fixtures\london.raw') print raw_data_location; with open(raw_data_location, 'rb') as f: data = f.read(); returndata = type('',(object,),{"content": data})() requests.get = MagicMock(return_value = returndata) @with_setup(setup) def test_geolocate_London(self): location = 'London'; result = self.mygraph.geolocate(location) assert_equal(values[location][0][1],result) @with_setup(setup) def test_geolocate_Oxford(self): location = 'Oxford'; result = self.mygraph.geolocate(location) assert_equal(values[location][0][1],result) @with_setup(setup) def test_location_sequence_London_To_Oxford(self): testresult = self.mygraph.location_sequence(self.london_location, self.oxford_location,5) assert_allclose(self.test_location_result,testresult,rtol=1e-5,atol=1e-8) @with_setup(setup) def test_location_sequence_Oxford_To_London(self): reversed_results = self.test_location_result[::-1] testresult = self.mygraph.location_sequence(self.oxford_location,self.london_location,5) assert_allclose(reversed_results,testresult,rtol=1e-5,atol=1e-8) @with_setup(setup) def test_location_sequence_Oxford_To_London_2steps(self): testresult = self.mygraph.location_sequence(self.oxford_location,self.london_location,2) assert_allclose([self.oxford_location, self.london_location],testresult,rtol=1e-5,atol=1e-8) @with_setup(setup) def test_graph_init_start_end(self): assert_equal(self.start,self.mygraph.start) assert_equal(self.end,self.mygraph.end) @with_setup(setup) def test_green_between_2_step(self): expected = [106725, 106725] result = self.mygraph.green_between(2) assert_equal(expected,result)
def do_the_thing(args): graph = Greengraph(args.start, args.end) if args.save_png: points = graph.location_sequence(graph.geolocate(graph.start), graph.geolocate(graph.end), args.steps) green = [] for n, point in enumerate(points): _m = Map(*point) green.append(_m.count_green()) with open(args.filename+'_'+str(n)+'.png','w') as f: f.write(_m.show_green()) else: green = graph.green_between(args.steps) plt.plot(graph.green_between(args.steps)) plt.savefig(args.filename+'.png') plt.show()