test_directory.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """ Python unittest script for bwi_logging/directory module.
00004 
00005 Does not require a ROS environment.
00006 """
00007 # enable some python3 compatibility options:
00008 from __future__ import absolute_import, print_function
00009 
00010 PKG='bwi_logging'
00011 import os
00012 import stat
00013 import unittest
00014 
00015 # module under test:
00016 from bwi_logging.directory import *
00017 
00018 
00019 def delete_file(filename):
00020     """ Delete a file, not complaining if it does not exist.
00021     :param filename: path to file.
00022     """
00023     try:
00024         os.remove(filename)
00025     except OSError:             # OK if file did not exist
00026         pass
00027 
00028 
00029 class TestLoggingDirectory(unittest.TestCase):
00030     """Unit tests for directory module. """
00031 
00032     def test_using_no_parameters(self):
00033         """ Test with neither parameter provided. """
00034         home = os.environ['HOME']
00035         ld = LoggingDirectory(None)
00036         d = home + '/.ros/bwi/bwi_logging'
00037         self.assertEqual(ld.pwd(), d)
00038         ld.chdir()
00039         self.assertEqual(os.getcwd(), d)
00040 
00041     def test_explicit_path_name(self):
00042         """ Test with explicit path name parameter. """
00043         um = os.umask(0o022)            # start by suppressing group write
00044         parent = '/tmp/bwi_logging'
00045         os.system('rm -rf ' + parent)
00046 
00047         # make sure at least two directories are created
00048         path = os.path.join(parent, 'tests')
00049         ld = LoggingDirectory(path)
00050         self.assertEqual(ld.pwd(), path)
00051         ld.chdir()
00052         self.assertEqual(os.getcwd(), path)
00053 
00054         # verify group write permissions
00055         st = os.stat(path)
00056         self.assertEqual(st.st_mode & stat.S_IWGRP, stat.S_IWGRP)
00057         os.umask(um)                    # restore umask permissions
00058 
00059 
00060 if __name__ == '__main__':
00061     import rosunit
00062     rosunit.unitrun(PKG, 'test_camera_info_manager',
00063                     TestCameraInfoManager)


bwi_logging
Author(s): Shiqi Zhang
autogenerated on Thu Jun 6 2019 17:57:20