示例#1
0
 def test_create_logfile_no_dir(self):
     '''
     Test new logfile creation in inexistant directory
     '''
     newlogfile = os.path.join(self.workdir, 'a/b', 'newtimelog.txt')
     self.assertFalse(os.path.exists(newlogfile),
                      '%s already exists' % newlogfile)
     argfile = [newlogfile]
     tl.set_logfile(argfile)
     self.assertTrue(os.path.exists(newlogfile),
                     '%s not created' % newlogfile)
示例#2
0
 def test_create_logfile_dir_exists(self):
     '''
     Test new logfile creation in directory that already exists
     '''
     newlogfile = os.path.join(self.workdir, 'c/d', 'newtimelog.txt')
     self.assertFalse(os.path.exists(newlogfile),
                      '%s already exists' % newlogfile)
     os.mkdir(self.workdir + '/c')
     argfile = [newlogfile]
     tl.set_logfile(argfile)
     self.assertTrue(os.path.exists(newlogfile),
                     '%s not created' % newlogfile)
示例#3
0
 def test_logfile_with_empty_env_variable(self):
     '''testing logfile definition with empty GTIMELOG_FILE env variable'''
     os.environ.setdefault('GTIMELOG_FILE', '')
     with patch('os.path.expanduser', return_value=self.workdir):
         with patch('os.path.exists', return_value=True):
             logfile = tl.set_logfile()
     default_target = '%s/.local/share/gtimelog/timelog.txt' % self.workdir
     self.assertEquals(logfile, default_target)
     os.environ.pop('GTIMELOG_FILE')
示例#4
0
 def test_logfile_env_variable(self):
     with patch('os.environ.get',
                return_value='%s/mylogenv' % self.workdir):
         Log = tl.set_logfile()
         self.assertEqual(Log, '%s/mylogenv' % self.workdir)
示例#5
0
 def test_logfile_arg(self):
     argline = ['%s/mylog' % self.workdir]
     Log = tl.set_logfile(argline)
     self.assertEqual(Log, '%s/mylog' % self.workdir)
示例#6
0
 def test_logfile_default(self):
     with patch('os.path.expanduser', return_value=self.workdir):
         with patch('tl.create_logfile', return_value=self.LogFile):
             Log = tl.set_logfile()
             self.assertEqual(
                 Log, '%s/.local/share/gtimelog/timelog.txt' % self.workdir)
示例#7
0
 def test_logfile_with_env_variable(self):
     '''testing logfile definition with GTIMELOG_FILE env variable'''
     os.environ.setdefault('GTIMELOG_FILE', '%s' % self.LogFile)
     logfile = tl.set_logfile()
     self.assertEquals(logfile, self.LogFile)
     os.environ.pop('GTIMELOG_FILE')
示例#8
0
 def test_logfile_with_arg(self):
     '''testing logfile definition with --logfile argument'''
     argfile = [self.LogFile]
     logfile = tl.set_logfile(argfile)
     self.assertTrue(logfile, self.LogFile)