def test_write_loadTheSameComplexData(self): """ Writing point cloud data and loading it afterwards should result in the same point cloud data. """ test_data = ComplexTestData() pc = test_data.get_point_cloud() export(pc, self.test_file_path) file = _get_file_from_path(self.test_file_path) _assert_all_attributes_in_file(pc[keys.point], file)
def test_check_is_compressed(self): """ Writing LAS file should not generate compressed file. """ test_data = ComplexTestData() pc = test_data.get_point_cloud() export(pc, self.test_file_path) file = _get_file_from_path(self.test_file_path) self.assertFalse(file.header.are_points_compressed)
def test_write_sameFileTwice(self): """ Should throw an exception. """ pc = SimpleTestData.get_point_cloud() export(pc, self.test_file_path) # Catch most specific subclass of FileExistsError (3.6) and IOError (2.7). with pytest.raises(Exception): export(pc, self.test_file_path)
def test_write_invalidAttributes(self): """ Should raise exception. """ test_data = ComplexTestData() pc = test_data.get_point_cloud() with pytest.raises(ValueError): export(pc, self.test_file_path, attributes=None) with pytest.raises(ValueError): export(pc, self.test_file_path, attributes=['ytisnetni'])
def test_write_loadTheSameSimpleHeader(self): """ Writing a simple point cloud and loading it afterwards should result in the same point cloud.""" pc_in = SimpleTestData.get_point_cloud() header_in = SimpleTestData.get_header() export(pc_in, self.test_file_path) with open(self.test_file_path, 'r') as ply: header_out = read_header(ply) self.assertMultiLineEqual(header_in, header_out)
def test_write_loadTheSameSimpleDataBinary(self): """ Writing point cloud data and loading it afterwards should result in the same point cloud data. """ pc_in = SimpleTestData.get_point_cloud() export(pc_in, self.test_file_path, is_binary=True) data_in = SimpleTestData.get_data(is_binary=True) with open(self.test_file_path, 'rb') as ply: data_out = read_data_binary(ply) self.assertEqual(data_in, data_out)
def test_write_loadTheSameComplexHeaderBinary(self): """ Writing point cloud data and loading it afterwards should result in the same point cloud data. """ test_data = ComplexTestData() pc_in = test_data.get_point_cloud() header_in = test_data.get_header(is_binary=True) export(pc_in, self.test_file_path, is_binary=True) with open(self.test_file_path, 'rb') as ply: header_out = read_header(ply, is_binary=True) self.assertEqual(header_in, header_out)
def test_write_loadTheSameComplexData(self): """ Writing point cloud data and loading it afterwards should result in the same point cloud data. """ test_data = ComplexTestData() pc_in = test_data.get_point_cloud() export(pc_in, self.test_file_path) data_in = test_data.get_data() with open(self.test_file_path, 'r') as ply: data_out = read_data_ascii(ply) self.assertEqual(data_in, data_out)
def test_write_processedRealData(self): """ Writing point cloud data and loading it afterwards should result in the same point cloud data. """ pc = load(self.load_file_path) x = pc[keys.point]['x']['data'] pc[keys.point]['test_feature'] = { 'data': np.zeros_like(x), 'type': 'float64' } export(pc, self.test_file_path) file = _get_file_from_path(self.test_file_path) _assert_all_attributes_in_file(pc[keys.point], file)
def export_point_cloud(self, filename='', overwrite=False): """ Export the classified point cloud :param filename: filename where to write point-cloud data :param overwrite: if file exists, overwrite """ if pathlib.Path(filename).parent.name: raise IOError('filename should not include path!') if not filename: filename = '_classification'.join( [self.input_path.stem, self.input_path.suffix]) export_path = (self.output_folder / filename).as_posix() export(self.point_cloud, export_path, overwrite=overwrite) return self
def test_write_loadRealData(self): """ Writing point cloud data and loading it afterwards should result in the same point cloud data. """ pc = load(self.load_file_path) export(pc, self.test_file_path) file = _get_file_from_path(self.test_file_path) _assert_all_attributes_in_file(pc[keys.point], file)
def test_write_sameFileTwiceOverwrite(self): """ Should not raise an exception """ pc = SimpleTestData.get_point_cloud() export(pc, self.test_file_path) export(pc, self.test_file_path, overwrite=True) self.assertTrue(os.path.isfile(self.test_file_path))
def test_write_sameFileTwice(self): """ Should raise an exception """ pc = SimpleTestData.get_point_cloud() export(pc, self.test_file_path) with pytest.raises(FileExistsError): export(pc, self.test_file_path)
def test_write_nonExistentDir(self): """ Should raise an exception """ pc = SimpleTestData.get_point_cloud() with pytest.raises(FileNotFoundError): export(pc, os.path.join('/nonexistentdir', self._test_file_name))
def test_write_emptyData(self): """ Should raise an exception """ pc = create_point_cloud([], [], []) with pytest.raises(ValueError): export(pc, self.test_file_path)
def test_write_nonExistingFile(self): """ Should create a file. """ pc = SimpleTestData.get_point_cloud() export(pc, self.test_file_path) assert (os.path.exists(self.test_file_path))