Skip to content
Snippets Groups Projects
Commit aa5b9c48 authored by paul.tresson_ird.fr's avatar paul.tresson_ird.fr
Browse files

first draft for unit tests

parent 7471f667
No related branches found
No related tags found
No related merge requests found
import os
import hashlib
import unittest
from qgis.core import QgsProcessingContext, QgsProcessingFeedback
from ..clustering import ClusterAlgorithm
## for hashing without using to much memory
BUF_SIZE = 65536
class TestClusteringAlgorithm(unittest.TestCase):
def setUp(self):
self.context = QgsProcessingContext()
self.feedback = QgsProcessingFeedback()
self.algorithm = ClusterAlgorithm()
def test_valid_parameters(self):
self.algorithm.initAlgorithm()
parameters = {}
result = self.algorithm.processAlgorithm(parameters, self.context, self.feedback)
expected_result_path = os.path.join(self.algorithm.output_dir,'cluster.tif')
md5 = hashlib.md5()
with open(expected_result_path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
md5.update(data)
result_file_hash = md5.hexdigest()
assert result_file_hash == 'd316fa71b627ee361786154118101f0e'
if __name__ == "__main__":
test_algo = TestClusteringAlgorithm()
test_algo.setUp()
test_algo.test_valid_parameters()
import os
import hashlib
import unittest
from qgis.core import QgsProcessingContext, QgsProcessingFeedback
from ..encoder import EncoderAlgorithm
## for hashing without using to much memory
BUF_SIZE = 65536
class TestEncoderAlgorithm(unittest.TestCase):
def setUp(self):
self.context = QgsProcessingContext()
self.feedback = QgsProcessingFeedback()
self.algorithm = EncoderAlgorithm()
def test_valid_parameters(self):
self.algorithm.initAlgorithm()
parameters = {}
result = self.algorithm.processAlgorithm(parameters, self.context, self.feedback)
expected_result_path = os.path.join(self.algorithm.output_subdir,'merged.tif')
md5 = hashlib.md5()
with open(expected_result_path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
md5.update(data)
result_file_hash = md5.hexdigest()
assert result_file_hash == '018b6fc5d88014a7e515824d95ca8686'
if __name__ == "__main__":
test_encoder = TestEncoderAlgorithm()
test_encoder.setUp()
test_encoder.test_valid_parameters()
import os
import hashlib
import unittest
from qgis.core import QgsProcessingContext, QgsProcessingFeedback
from ..reduction import ReductionAlgorithm
## for hashing without using to much memory
BUF_SIZE = 65536
class TestReductionAlgorithm(unittest.TestCase):
def setUp(self):
self.context = QgsProcessingContext()
self.feedback = QgsProcessingFeedback()
self.algorithm = ReductionAlgorithm()
def test_valid_parameters(self):
self.algorithm.initAlgorithm()
parameters = {}
result = self.algorithm.processAlgorithm(parameters, self.context, self.feedback)
expected_result_path = os.path.join(self.algorithm.output_dir,'proj.tif')
md5 = hashlib.md5()
with open(expected_result_path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
md5.update(data)
result_file_hash = md5.hexdigest()
assert result_file_hash == 'e47ca7b39f252506526a1ebfa1f33f6c'
if __name__ == "__main__":
test_algo = TestReductionAlgorithm()
test_algo.setUp()
test_algo.test_valid_parameters()
import os
import hashlib
import unittest
from qgis.core import QgsProcessingContext, QgsProcessingFeedback
from ..random_forest import RFAlgorithm
## for hashing without using to much memory
BUF_SIZE = 65536
class TestRFAlgorithm(unittest.TestCase):
def setUp(self):
self.context = QgsProcessingContext()
self.feedback = QgsProcessingFeedback()
self.algorithm = RFAlgorithm()
def test_valid_parameters(self):
self.algorithm.initAlgorithm()
parameters = {}
result = self.algorithm.processAlgorithm(parameters, self.context, self.feedback)
expected_result_path = os.path.join(self.algorithm.output_dir,'random_forest.tif')
md5 = hashlib.md5()
with open(expected_result_path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
md5.update(data)
result_file_hash = md5.hexdigest()
assert result_file_hash == '80b7dd5b5ad5a4c0ad1d637fa20cf8b0'
if __name__ == "__main__":
test_algo = TestRFAlgorithm()
test_algo.setUp()
test_algo.test_valid_parameters()
import os
import hashlib
import unittest
from qgis.core import QgsProcessingContext, QgsProcessingFeedback
from ..similarity import SimilarityAlgorithm
## for hashing without using to much memory
BUF_SIZE = 65536
class TestSimilarityAlgorithm(unittest.TestCase):
def setUp(self):
self.context = QgsProcessingContext()
self.feedback = QgsProcessingFeedback()
self.algorithm = SimilarityAlgorithm()
def test_valid_parameters(self):
self.algorithm.initAlgorithm()
parameters = {}
result = self.algorithm.processAlgorithm(parameters, self.context, self.feedback)
expected_result_path = os.path.join(self.algorithm.output_dir,'similarity.tif')
md5 = hashlib.md5()
with open(expected_result_path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
md5.update(data)
result_file_hash = md5.hexdigest()
assert result_file_hash == 'f76eb1f0469725b49fe0252cfe86829a'
if __name__ == "__main__":
test_algo = TestSimilarityAlgorithm()
test_algo.setUp()
test_algo.test_valid_parameters()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment