Repository: azavea/raster-vision

Issue:
Unit Tests: `command` Directory



Discussion:

Resolving patch:
diff --git a/rastervision/utils/files.py b/rastervision/utils/files.py
--- a/rastervision/utils/files.py
+++ b/rastervision/utils/files.py
@@ -73,7 +73,8 @@ def sync_from_dir(src_dir_uri, dest_dir_uri, delete=False, fs=None):
     fs.sync_from_dir(src_dir_uri, dest_dir_uri, delete=delete)
 
 
-def start_sync(src_dir_uri, dest_dir_uri, sync_interval=600, fs=None):
+def start_sync(src_dir_uri, dest_dir_uri, sync_interval=600,
+               fs=None):  # pragma: no cover
     """Start syncing a directory on a schedule.
 
     Calls sync_to_dir on a schedule.
@@ -157,7 +158,7 @@ def file_exists(uri, fs=None):
     return fs.file_exists(uri)
 
 
-def list_paths(uri, ext=None, fs=None):
+def list_paths(uri, ext='', fs=None):
     if uri is None:
         return None
 


Test patch:
diff --git a/scripts/unit_tests b/scripts/unit_tests
--- a/scripts/unit_tests
+++ b/scripts/unit_tests
@@ -22,6 +22,6 @@ else
     if ! [ -x "$(command -v coverage)" ]; then
 	python -m unittest discover tests
     else
-	coverage run --source=rastervision '--omit=rastervision/protos/**.py' -m unittest discover tests
+	coverage run -m unittest discover tests
     fi
 fi
diff --git a/tests/command/__init__.py b/tests/command/__init__.py
new file mode 100644
diff --git a/tests/command/test_analyze_command_config.py b/tests/command/test_analyze_command_config.py
--- a/tests/command/test_analyze_command_config.py
+++ b/tests/command/test_analyze_command_config.py
@@ -1,16 +1,30 @@
 import unittest
 
 import rastervision as rv
+from rastervision.rv_config import RVConfig
 
 
 class TestAnalyzeCommand(unittest.TestCase):
+    def test_command_create(self):
+        with RVConfig.get_tmp_dir() as tmp_dir:
+            cmd = rv.command.AnalyzeCommandConfig.builder() \
+                                                 .with_task('') \
+                                                 .with_root_uri(tmp_dir) \
+                                                 .with_scenes('') \
+                                                 .with_analyzers('') \
+                                                 .build() \
+                                                 .create_command()
+            self.assertTrue(cmd, rv.command.AnalyzeCommand)
+
     def test_no_config_error(self):
         try:
-            rv.command.AnalyzeCommandConfig.builder() \
-                                           .with_task('') \
-                                           .with_scenes('') \
-                                           .with_analyzers('') \
-                                           .build()
+            with RVConfig.get_tmp_dir() as tmp_dir:
+                rv.command.AnalyzeCommandConfig.builder() \
+                                               .with_task('') \
+                                               .with_root_uri(tmp_dir) \
+                                               .with_scenes('') \
+                                               .with_analyzers('') \
+                                               .build()
         except rv.ConfigError:
             self.fail('rv.ConfigError raised unexpectedly')
 
diff --git a/tests/command/test_bundle_command.py b/tests/command/test_bundle_command.py
--- a/tests/command/test_bundle_command.py
+++ b/tests/command/test_bundle_command.py
@@ -67,6 +67,7 @@ def get_backend(task, tmp_dir):
             scene = self.get_scene(tmp_dir)
             cmd = BundleCommandConfig.builder() \
                                      .with_task(task) \
+                                     .with_root_uri(tmp_dir) \
                                      .with_backend(backend) \
                                      .with_analyzers([analyzer]) \
                                      .with_scene(scene) \
@@ -121,6 +122,7 @@ def get_backend(task, tmp_dir):
             scene = self.get_scene(tmp_dir)
             cmd = BundleCommandConfig.builder() \
                                      .with_task(task) \
+                                     .with_root_uri(tmp_dir) \
                                      .with_backend(backend) \
                                      .with_analyzers([analyzer]) \
                                      .with_scene(scene) \
diff --git a/tests/command/test_chip_command_config.py b/tests/command/test_chip_command_config.py
--- a/tests/command/test_chip_command_config.py
+++ b/tests/command/test_chip_command_config.py
@@ -1,9 +1,22 @@
 import unittest
 
 import rastervision as rv
+from rastervision.rv_config import RVConfig
 
 
 class TestChipCommand(unittest.TestCase):
+    def test_command_create(self):
+        with RVConfig.get_tmp_dir() as tmp_dir:
+            cmd = rv.command.ChipCommandConfig.builder() \
+                                              .with_task('') \
+                                              .with_backend('') \
+                                              .with_train_scenes('') \
+                                              .with_val_scenes('') \
+                                              .with_root_uri(tmp_dir) \
+                                              .build() \
+                                              .create_command()
+            self.assertTrue(cmd, rv.command.ChipCommand)
+
     def test_missing_config_task(self):
         with self.assertRaises(rv.ConfigError):
             rv.command.ChipCommandConfig.builder() \
@@ -38,12 +51,14 @@ def test_missing_config_val_scenes(self):
 
     def test_no_config_error(self):
         try:
-            rv.command.ChipCommandConfig.builder() \
-                                        .with_task('') \
-                                        .with_backend('') \
-                                        .with_train_scenes('') \
-                                        .with_val_scenes('') \
-                                        .build()
+            with RVConfig.get_tmp_dir() as tmp_dir:
+                rv.command.ChipCommandConfig.builder() \
+                                            .with_task('') \
+                                            .with_root_uri(tmp_dir) \
+                                            .with_backend('') \
+                                            .with_train_scenes('') \
+                                            .with_val_scenes('') \
+                                            .build()
         except rv.ConfigError:
             self.fail('rv.ConfigError raised unexpectedly')
 
diff --git a/tests/command/test_eval_command.py b/tests/command/test_eval_command.py
--- a/tests/command/test_eval_command.py
+++ b/tests/command/test_eval_command.py
@@ -1,9 +1,21 @@
 import unittest
 
 import rastervision as rv
+from rastervision.rv_config import RVConfig
 
 
 class TestEvalCommand(unittest.TestCase):
+    def test_command_create(self):
+        with RVConfig.get_tmp_dir() as tmp_dir:
+            cmd = rv.command.EvalCommandConfig.builder() \
+                                              .with_task('') \
+                                              .with_root_uri(tmp_dir) \
+                                              .with_scenes('') \
+                                              .with_evaluators('') \
+                                              .build() \
+                                              .create_command()
+            self.assertTrue(cmd, rv.command.EvalCommand)
+
     def test_missing_config_task(self):
         with self.assertRaises(rv.ConfigError):
             rv.command.EvalCommandConfig.builder() \
@@ -27,11 +39,13 @@ def test_missing_config_evaluators(self):
 
     def test_no_config_error(self):
         try:
-            rv.command.EvalCommandConfig.builder() \
-                                        .with_task('') \
-                                        .with_scenes('') \
-                                        .with_evaluators('') \
-                                        .build()
+            with RVConfig.get_tmp_dir() as tmp_dir:
+                rv.command.EvalCommandConfig.builder() \
+                                            .with_task('') \
+                                            .with_root_uri(tmp_dir) \
+                                            .with_scenes('') \
+                                            .with_evaluators('') \
+                                            .build()
         except rv.ConfigError:
             self.fail('rv.ConfigError raised unexpectedly')
 
diff --git a/tests/command/test_predict_command.py b/tests/command/test_predict_command.py
--- a/tests/command/test_predict_command.py
+++ b/tests/command/test_predict_command.py
@@ -1,9 +1,21 @@
 import unittest
 
 import rastervision as rv
+from rastervision.rv_config import RVConfig
 
 
 class PredictCommand(unittest.TestCase):
+    def test_command_create(self):
+        with RVConfig.get_tmp_dir() as tmp_dir:
+            cmd = rv.command.PredictCommandConfig.builder() \
+                                                 .with_task('') \
+                                                 .with_root_uri(tmp_dir) \
+                                                 .with_scenes('') \
+                                                 .with_backend('') \
+                                                 .build() \
+                                                 .create_command()
+            self.assertTrue(cmd, rv.command.PredictCommand)
+
     def test_missing_config_task(self):
         with self.assertRaises(rv.ConfigError):
             rv.command.PredictCommandConfig.builder() \
@@ -27,11 +39,13 @@ def test_missing_config_scenes(self):
 
     def test_no_config_error(self):
         try:
-            rv.command.PredictCommandConfig.builder() \
-                                           .with_task('') \
-                                           .with_backend('') \
-                                           .with_scenes(['']) \
-                                           .build()
+            with RVConfig.get_tmp_dir() as tmp_dir:
+                rv.command.PredictCommandConfig.builder() \
+                                               .with_task('') \
+                                               .with_root_uri(tmp_dir) \
+                                               .with_backend('') \
+                                               .with_scenes(['']) \
+                                               .build()
         except rv.ConfigError:
             self.fail('rv.ConfigError raised unexpectedly')
 
diff --git a/tests/command/test_train_command.py b/tests/command/test_train_command.py
--- a/tests/command/test_train_command.py
+++ b/tests/command/test_train_command.py
@@ -1,6 +1,7 @@
 import unittest
 
 import rastervision as rv
+from rastervision.rv_config import RVConfig
 
 
 class TrainCommand(unittest.TestCase):
@@ -18,10 +19,12 @@ def test_missing_config_backend(self):
 
     def test_no_config_error(self):
         try:
-            rv.command.TrainCommandConfig.builder() \
-                                         .with_task('') \
-                                         .with_backend('') \
-                                         .build()
+            with RVConfig.get_tmp_dir() as tmp_dir:
+                rv.command.TrainCommandConfig.builder() \
+                                             .with_task('') \
+                                             .with_root_uri(tmp_dir) \
+                                             .with_backend('') \
+                                             .build()
         except rv.ConfigError:
             self.fail('rv.ConfigError raised unexpectedly')
 
diff --git a/tests/utils/test_files.py b/tests/utils/test_files.py
--- a/tests/utils/test_files.py
+++ b/tests/utils/test_files.py
@@ -10,7 +10,7 @@
 from rastervision.utils.files import (
     file_to_str, str_to_file, download_if_needed, upload_or_copy,
     load_json_config, ProtobufParseException, make_dir, get_local_path,
-    file_exists, sync_from_dir, sync_to_dir)
+    file_exists, sync_from_dir, sync_to_dir, list_paths)
 from rastervision.filesystem import (NotReadableError, NotWritableError)
 from rastervision.filesystem.filesystem import FileSystem
 from rastervision.protos.task_pb2 import TaskConfig as TaskConfigMsg
@@ -328,13 +328,12 @@ def test_list_paths_s3(self):
         directory = os.path.dirname(path)
         make_dir(directory, check_empty=False)
 
-        fs = FileSystem.get_file_system(s3_path, 'r')
-
         with open(path, 'w+') as file:
             file.write(self.lorem)
         upload_or_copy(path, s3_path)
 
-        self.assertEqual(len(fs.list_paths(s3_directory)), 1)
+        list_paths(s3_directory)
+        self.assertEqual(len(list_paths(s3_directory)), 1)
 
 
 class TestLocalMisc(unittest.TestCase):
@@ -374,7 +373,7 @@ def test_sync_from_dir_local(self):
         fs.write_bytes(path, bytes([0x00, 0x01]))
         sync_from_dir(src, dst, delete=True)
 
-        self.assertEqual(len(fs.list_paths(dst)), 1)
+        self.assertEqual(len(list_paths(dst)), 1)
 
     def test_sync_from_dir_noop_local(self):
         path = os.path.join(self.temp_dir.name, 'lorem', 'ipsum.txt')
@@ -385,7 +384,7 @@ def test_sync_from_dir_noop_local(self):
         fs.write_bytes(path, bytes([0x00, 0x01]))
         sync_from_dir(src, src, delete=True)
 
-        self.assertEqual(len(fs.list_paths(src)), 1)
+        self.assertEqual(len(list_paths(src)), 1)
 
     def test_sync_to_dir_local(self):
         path = os.path.join(self.temp_dir.name, 'lorem', 'ipsum.txt')
@@ -398,7 +397,7 @@ def test_sync_to_dir_local(self):
         fs.write_bytes(path, bytes([0x00, 0x01]))
         sync_to_dir(src, dst, delete=True)
 
-        self.assertEqual(len(fs.list_paths(dst)), 1)
+        self.assertEqual(len(list_paths(dst)), 1)
 
     def test_copy_to_local(self):
         path1 = os.path.join(self.temp_dir.name, 'lorem', 'ipsum.txt')
@@ -411,9 +410,8 @@ def test_copy_to_local(self):
         with open(path1, 'w+') as file:
             file.write(self.lorem)
 
-        fs = FileSystem.get_file_system(path1, 'r')
         upload_or_copy(path1, path2)
-        self.assertEqual(len(fs.list_paths(dir2)), 1)
+        self.assertEqual(len(list_paths(dir2)), 1)
 
     def test_last_modified(self):
         path = os.path.join(self.temp_dir.name, 'lorem', 'ipsum1.txt')