#!/usr/bin/env python
""" Tests for YATSM scripts
"""
import os
import shutil
import unittest

from utils_testing import TestMaps


class Test_YATSMMap(TestMaps):

    def setUp(self):
        """ Setup test data filenames and load known truth dataset """
        self.script = 'yatsm_map.py'

        # Test data
        self.root = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'data')
        self.result_dir = os.path.join(self.root, 'YATSM')
        self.robust_result_dir = os.path.join(self.root, 'YATSM_ROBUST')
        self.data_cache = os.path.join(self.root, 'cache')
        self.example_img = os.path.join(self.root, 'example_img')
        self.outdir = os.path.join(self.root, 'outdir')

        # Answers
        self.answers = os.path.join(self.root, 'answers')

        if not os.path.isdir(self.outdir):
            os.makedirs(self.outdir)

    def tearDown(self):
        """ Deletes answer directory """
        if os.path.isdir(self.outdir):
            shutil.rmtree(self.outdir)

# Test coefficients
    def test_coef(self):
        """ Test creating coefficient map """
        output = os.path.join(self.outdir, 'coef_all.gtif')

        args = '--root {r} coef 2000-06-01 {o}'.format(
            r=self.root,
            o=output).split(' ')

        msg, retcode = self._run(self.script, args)
        self.assertEqual(retcode, 0)

        # Test output
        self._compare_maps(os.path.join(self.outdir, output),
                           os.path.join(self.answers, output))

    def test_coef_robust(self):
        """ Test creating robust coefficient map """
        output = 'coef_all_robust.gtif'

        # Test robust coefficients
        args = '--root {r} --result {rr} --robust coef 2000-06-01 {o}'.format(
            r=self.root,
            rr=self.robust_result_dir,
            o=os.path.join(self.outdir, output)).split(' ')

        msg, retcode = self._run(self.script, args)
        self.assertEqual(retcode, 0)

        # Test robust coefficients, expecting error
        args = '--root {r} --robust coef 2000-06-01 {o}'.format(
            r=self.root,
            o=os.path.join(self.outdir, output)).split(' ')
        msg, retcode = self._run(self.script, args)

        self.assertEqual(retcode, 1)

        # Test output
        self._compare_maps(os.path.join(self.outdir, output),
                           os.path.join(self.answers, output))

    def test_coef_bands(self):
        """ Test if correct bands are output """
        # Test bands outputs
        # Test coefficient outputs
        pass

    def test_coef_before_after(self):
        """ Test use of --before and --after flags """
        pass

# Test prediction
# Test classification
# Test optional arguments
    def test_ndv(self):
        """ Test output file NoDataValue """
        pass

    def test_output_format(self):
        """ Test output GDAL file format """
        pass

    def test_date_format(self):
        """ Test input date format type """
        pass


class Test_YATSMChangeMap(TestMaps):

    def setUp(self):
        """ Setup test data filenames and load known truth dataset """
        self.script = 'yatsm_changemap.py'

        # Test data
        self.root = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'data')
        self.result_dir = os.path.join(self.root, 'YATSM')
        self.robust_result_dir = os.path.join(self.root, 'YATSM_ROBUST')
        self.data_cache = os.path.join(self.root, 'cache')
        self.example_img = os.path.join(self.root, 'example_img')
        self.outdir = os.path.join(self.root, 'outdir')

        # Answers
        self.answers = os.path.join(self.root, 'answers')

        if not os.path.isdir(self.outdir):
            os.makedirs(self.outdir)

    def tearDown(self):
        """ Deletes answer directory """
        if os.path.isdir(self.outdir):
            shutil.rmtree(self.outdir)

    def test_numchange(self):
        pass


if __name__ == '__main__':
    unittest.main()

@@ -99,20 +99,20 @@
 m utils_
-test
+mapp
 ing impo
@@ -157,38 +157,59 @@
 Maps):%0A%0A    
-def setUp(self
+@classmethod%0A    def setUpClass(cls
 ):%0A        %22
@@ -270,36 +270,35 @@
 set %22%22%22%0A        
-self
+cls
 .script = 'yatsm
@@ -327,36 +327,35 @@
 st data%0A        
-self
+cls
 .root = os.path.
@@ -424,36 +424,35 @@
 'data')%0A        
-self
+cls
 .result_dir = os
@@ -454,36 +454,35 @@
  = os.path.join(
-self
+cls
 .root, 'YATSM')%0A
@@ -481,36 +481,35 @@
 YATSM')%0A        
-self
+cls
 .robust_result_d
@@ -518,36 +518,35 @@
  = os.path.join(
-self
+cls
 .root, 'YATSM_RO
@@ -552,36 +552,35 @@
 OBUST')%0A        
-self
+cls
 .data_cache = os
@@ -582,36 +582,35 @@
  = os.path.join(
-self
+cls
 .root, 'cache')%0A
@@ -609,36 +609,35 @@
 cache')%0A        
-self
+cls
 .example_img = o
@@ -640,36 +640,35 @@
  = os.path.join(
-self
+cls
 .root, 'example_
@@ -673,36 +673,35 @@
 e_img')%0A        
-self
+cls
 .outdir = os.pat
@@ -699,36 +699,35 @@
  = os.path.join(
-self
+cls
 .root, 'outdir')
@@ -746,36 +746,35 @@
 Answers%0A        
-self
+cls
 .answers = os.pa
@@ -773,36 +773,35 @@
  = os.path.join(
-self
+cls
 .root, 'answers'
@@ -824,36 +824,35 @@
 t os.path.isdir(
-self
+cls
 .outdir):%0A      
@@ -861,36 +861,35 @@
     os.makedirs(
-self
+cls
 .outdir)%0A%0A    de
@@ -874,32 +874,49 @@
 rs(cls.outdir)%0A%0A
+    @classmethod%0A
     def tearDown
@@ -907,37 +907,41 @@
     def tearDown
-(self
+Class(cls
 ):%0A        %22%22%22 D
@@ -985,36 +985,35 @@
 f os.path.isdir(
-self
+cls
 .outdir):%0A      
@@ -1024,36 +1024,35 @@
   shutil.rmtree(
-self
+cls
 .outdir)%0A%0A# Test

Switch to setupClass and tearDownClass so it only happens once