drakeutil / test_drakeutil.py

# -*- coding: utf-8 -*-
#
#  test_drakeutil.py
#  drakeutil
#

"""
Tests for drake helpers.
"""

import unittest
from datetime_tz import datetime_tz as datetime
import os
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(self.du.file_timestamp(__file__), expected)

    def test_file_mtime_missing(self):
        self.assertEquals(self.du.file_timestamp(__file__ + '.unlikely'),
                None)


class DrakeEnvTest(unittest.TestCase):
    def setUp(self):
        os.environ['INPUT'] = 'input'
        os.environ['OUTPUT'] = 'output'
        os.environ['INPUTS'] = 'input0 input1 input2'
        os.environ['OUTPUTS'] = 'output0 output1 output2'
        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')
        self.assertEquals(self.du.INPUTS, ['input0', 'input1', 'input2'])
        self.assertEquals(self.du.OUTPUTS, ['output0', 'output1', 'output2'])


def suite():
    return unittest.TestSuite((
            unittest.makeSuite(DrakeHelperTest),
            unittest.makeSuite(DrakeEnvTest),
        ))


if __name__ == '__main__':
    unittest.TextTestRunner(verbosity=1).run(suite())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.