1. Lars Yencken
  2. drakeutil

Commits

Lars Yencken  committed 386d8b6

Pass through drake special variables.

  • Participants
  • Parent commits e563b10
  • Branches master

Comments (0)

Files changed (2)

File drakeutil/__init__.py

View file
  • Ignore whitespace
 """
 
 from shutil import copy, move, copytree, rmtree  # noqa
-from os import path, rename, stat  # noqa
+from os import environ, path, rename, stat  # noqa
 from datetime_tz import datetime_tz
 
 import subprocess
 
 
+# set up special drake environment variables
+for k in environ:
+    if k.startswith('INPUT') or k.startswith('OUTPUT'):
+        locals()[k] = environ[k]
+
+
 def hdfs_timestamp(filename):
     "When was this file last modified?"
     stdout, stderr = subprocess.Popen(['hadoop', 'fs', '-stat', filename],

File test_drakeutil.py

View file
  • Ignore whitespace
 import unittest
 from datetime_tz import datetime_tz as datetime
 import os
-
-import drakeutil
+import sys
 
 
 class DrakeHelperTest(unittest.TestCase):
+    def setUp(self):
+        if 'drakeutil' in sys.modules:
+            del sys.modules['drakeutil']
+        self.du = __import__('drakeutil')
+
     def test_file_mtime(self):
         expected = datetime.utcfromtimestamp(
                 os.stat(__file__).st_mtime
             )
-        self.assertEquals(drakeutil.file_timestamp(__file__), expected)
+        self.assertEquals(self.du.file_timestamp(__file__), expected)
 
     def test_file_mtime_missing(self):
-        self.assertEquals(drakeutil.file_timestamp(__file__ + '.unlikely'),
+        self.assertEquals(self.du.file_timestamp(__file__ + '.unlikely'),
                 None)
 
 
+class DrakeEnvTest(unittest.TestCase):
+    def setUp(self):
+        os.environ['INPUT'] = 'input'
+        os.environ['OUTPUT'] = 'output'
+        if 'drakeutil' in sys.modules:
+            del sys.modules['drakeutil']
+        self.du = __import__('drakeutil')
+
+    def test_special(self):
+        self.assertEquals(self.du.INPUT, 'input')
+        self.assertEquals(self.du.OUTPUT, 'output')
+
+
+def suite():
+    return unittest.TestSuite((
+            unittest.makeSuite(DrakeHelperTest),
+            unittest.makeSuite(DrakeEnvTest),
+        ))
+
+
 if __name__ == '__main__':
-    unittest.TextTestRunner(verbosity=1).run(
-            unittest.makeSuite(DrakeHelperTest)
-        )
+    unittest.TextTestRunner(verbosity=1).run(suite())