Repository: DataKind-SG/test-driven-data-cleaning

Issue:
run_tddc and __main__ are not both needed
move everything in run_tddc to \_\_main\_\_

Discussion:

Patch:
diff --git a/tddc/__main__.py b/tddc/__main__.py
index 0749707..208b1c5 100644
--- a/tddc/__main__.py
+++ b/tddc/__main__.py
@@ -1,6 +1,58 @@
+"""Test driven data cleaning
+Usage:
+  tddc summarize <input_file> [--output=<dir>] [--null=<NA>]
+  tddc build_trello <input_file> [--output=<dir>]
+  tddc build <input_file> [--output=<dir>]
+  tddc -h | --help
+  tddc --version
+
+Options:
+  -h --help       Show this screen.
+  --version       Show version.
+  --output=<dir>  Output directory [default: output]
+  --null=<NA>     Null string [default: NA]
+"""
+from docopt import docopt
 import os
 import sys
-import tddc.run_tddc
+
+import tddc
+from tddc import summarize, build_trello, build
+
+
+def get_input_root_dir():
+    return os.getcwd()
+
+
+def get_output_root_dir():
+    return os.getcwd()
+
+
+def execute(cli_args):
+    arguments = docopt(__doc__, cli_args, version=tddc.__version__)
+    if arguments['summarize']:
+        summarize.go(
+            input_root_dir=get_input_root_dir(),
+            input_file=arguments['<input_file>'],
+            output_root_dir=get_output_root_dir(),
+            output_dir=arguments['--output'],
+            null_string=arguments['--null'],
+        )
+    elif arguments['build_trello']:
+        build_trello.go(
+            summary_root_dir=get_input_root_dir(),
+            input_file=arguments['<input_file>'],
+            trello_summary_root_dir=get_output_root_dir(),
+            output_dir=arguments['--output']
+        )
+    elif arguments['build']:
+        build.go(
+            summaries_root_dir=get_input_root_dir(),
+            input_file=arguments['<input_file>'],
+            scripts_root_dir=get_output_root_dir(),
+            output_dir=arguments['--output']
+        )
+
 
 if __name__ == '__main__':
-    tddc.run_tddc.execute(sys.argv[1:])
+    execute(sys.argv[1:])
diff --git a/tddc/run_tddc.py b/tddc/run_tddc.py
index 208b1c5..e69de29 100644
--- a/tddc/run_tddc.py
+++ b/tddc/run_tddc.py
@@ -1,58 +0,0 @@
-"""Test driven data cleaning
-Usage:
-  tddc summarize <input_file> [--output=<dir>] [--null=<NA>]
-  tddc build_trello <input_file> [--output=<dir>]
-  tddc build <input_file> [--output=<dir>]
-  tddc -h | --help
-  tddc --version
-
-Options:
-  -h --help       Show this screen.
-  --version       Show version.
-  --output=<dir>  Output directory [default: output]
-  --null=<NA>     Null string [default: NA]
-"""
-from docopt import docopt
-import os
-import sys
-
-import tddc
-from tddc import summarize, build_trello, build
-
-
-def get_input_root_dir():
-    return os.getcwd()
-
-
-def get_output_root_dir():
-    return os.getcwd()
-
-
-def execute(cli_args):
-    arguments = docopt(__doc__, cli_args, version=tddc.__version__)
-    if arguments['summarize']:
-        summarize.go(
-            input_root_dir=get_input_root_dir(),
-            input_file=arguments['<input_file>'],
-            output_root_dir=get_output_root_dir(),
-            output_dir=arguments['--output'],
-            null_string=arguments['--null'],
-        )
-    elif arguments['build_trello']:
-        build_trello.go(
-            summary_root_dir=get_input_root_dir(),
-            input_file=arguments['<input_file>'],
-            trello_summary_root_dir=get_output_root_dir(),
-            output_dir=arguments['--output']
-        )
-    elif arguments['build']:
-        build.go(
-            summaries_root_dir=get_input_root_dir(),
-            input_file=arguments['<input_file>'],
-            scripts_root_dir=get_output_root_dir(),
-            output_dir=arguments['--output']
-        )
-
-
-if __name__ == '__main__':
-    execute(sys.argv[1:])


Test patch:
diff --git a/tddc/tests/test_run_tddc.py b/tddc/tests/test_main.py
similarity index 83%
rename from tddc/tests/test_run_tddc.py
rename to tddc/tests/test_main.py
index 68ba0d2..a575056 100644
--- a/tddc/tests/test_run_tddc.py
+++ b/tddc/tests/test_main.py
@@ -2,7 +2,7 @@ import pytest
 import os
 from mock import patch
 
-from tddc import run_tddc, common
+from tddc import __main__, common
 
 
 @pytest.fixture(scope='module')
@@ -11,15 +11,15 @@ def root_dir():
 
 
 def test_get_input_root_dir(root_dir):
-    assert run_tddc.get_input_root_dir() == root_dir
+    assert __main__.get_input_root_dir() == root_dir
 
 
 def test_get_output_root_dir(root_dir):
-    assert run_tddc.get_output_root_dir() == root_dir
+    assert __main__.get_output_root_dir() == root_dir
 
 
-@patch('tddc.run_tddc.get_input_root_dir')
-@patch('tddc.run_tddc.get_output_root_dir')
+@patch('tddc.__main__.get_input_root_dir')
+@patch('tddc.__main__.get_output_root_dir')
 def test_cli_summarize(
         mock_output_root_dir, mock_input_root_dir, fixtures_dir, input_filename, null_string, tmpdir
 ):
@@ -37,12 +37,12 @@ def test_cli_summarize(
     # test_summarize.py already tests the content of the file. This just tests that the CLI works properly and
     # generates a file at the expected location.
     assert not os.path.isfile(expected_output_loc)
-    run_tddc.execute(cli_args)
+    __main__.execute(cli_args)
     assert os.path.isfile(expected_output_loc)
 
 
-@patch('tddc.run_tddc.get_input_root_dir')
-@patch('tddc.run_tddc.get_output_root_dir')
+@patch('tddc.__main__.get_input_root_dir')
+@patch('tddc.__main__.get_output_root_dir')
 @patch('tddc.build_trello.Trello.client')
 def test_cli_build_trello(
         mock_client, mock_output_root_dir, mock_input_root_dir, fixtures_dir, input_filename, tmpdir
@@ -64,5 +64,5 @@ def test_cli_build_trello(
     # test_build_trello.py already tests the content of the file. This just tests that the CLI works properly and
     # generates a file at the expected location.
     assert not os.path.isfile(expected_output_loc)
-    run_tddc.execute(cli_args)
+    __main__.execute(cli_args)
     assert os.path.isfile(expected_output_loc)