Example #1
0
 def test_shortcut(self):
     """Test that we can use display shortcuts with __getattr__."""
     # Create map
     grass_renderer = gj.GrassRenderer()
     # Use shortcut
     grass_renderer.d_rast(map="elevation")
     grass_renderer.d_vect(map="roadsmajor")
Example #2
0
 def test_filename_property(self):
     """Test of GrassRenderer filename property."""
     # Create map with unique filename
     grass_renderer = gj.GrassRenderer()
     grass_renderer.run("d.rast", map="elevation")
     # Make sure image was created
     self.assertFileExists(grass_renderer.filename)
Example #3
0
 def test_defaults(self):
     """Test that GrassRenderer can create a map with default settings."""
     # Create a map with default inputs
     grass_renderer = gj.GrassRenderer()
     # Adding vectors and rasters to the map
     grass_renderer.run("d.rast", map="elevation")
     grass_renderer.run("d.vect", map="roadsmajor")
     # Make sure image was created
     self.assertFileExists(grass_renderer._filename)
Example #4
0
 def test_shortcut_error(self):
     """Test that passing an incorrect attribute raises
     appropriate error"""
     # Create map
     grass_renderer = gj.GrassRenderer()
     # Pass bad shortcuts
     with self.assertRaisesRegex(AttributeError, "Module must begin with 'd_'"):
         grass_renderer.r_watersheds()
     with self.assertRaisesRegex(AttributeError, "d.module.does.not.exist"):
         grass_renderer.d_module_does_not_exist()
Example #5
0
 def test_filename(self):
     """Test that GrassRenderer creates maps with unique filenames."""
     # Create map with unique filename
     custom_filename = "test_filename.png"
     grass_renderer = gj.GrassRenderer(filename=custom_filename)
     # Add files to self for cleanup later
     self.files.append(custom_filename)
     self.files.append(f"{custom_filename}.grass_vector_legend")
     # Add a vector and a raster to the map
     grass_renderer.run("d.rast", map="elevation")
     grass_renderer.run("d.vect", map="roadsmajor")
     # Make sure image was created
     self.assertFileExists(custom_filename)
Example #6
0
 def test_image_creation(self):
     """Test that show() returns an image object."""
     # Create map
     grass_renderer = gj.GrassRenderer()
     grass_renderer.d_rast(map="elevation")
     self.assertTrue(grass_renderer.show(), "Failed to open PNG image")
Example #7
0
 def test_text(self):
     """Test that we can set a unique text_size in GrassRenderer."""
     # Create map with unique text_size parameter
     grass_renderer = gj.GrassRenderer(text_size=10)
     grass_renderer.run("d.vect", map="roadsmajor")
     grass_renderer.run("d.rast", map="elevation")
Example #8
0
 def test_env(self):
     """Test that we can hand an environment to GrassRenderer."""
     # Create map with environment parameter
     grass_renderer = gj.GrassRenderer(env=os.environ.copy())
     # Add just a raster (again for variety)
     grass_renderer.run("d.rast", map="elevation")
Example #9
0
 def test_hw(self):
     """Test that GrassRenderer creates maps with custom height and widths."""
     # Create map with height and width parameters
     grass_renderer = gj.GrassRenderer(width=400, height=400)
     # Add just a vector (for variety here)
     grass_renderer.run("d.vect", map="roadsmajor")