示例#1
0
文件: tests.py 项目: scriada/timeflow
    def test_log(self):
        "Tests log command"
        # this tests needs separate log file
        helpers.LOG_FILE = self.test_dir + '/auto_fake_log.txt'

        args = parse_args(['log', 'loging message'])
        args.func(args)
        self.assertEqual(len(helpers.read_log_file_lines()), 1)
        # get message without datetime string and colon sign at the end of it
        msg_line = helpers.read_log_file_lines()[0]
        msg = msg_line[helpers.DATETIME_LEN+1:]
        self.assertEqual(msg, 'loging message\n')

        args = parse_args(['log', 'second loging message'])
        args.func(args)
        self.assertEqual(len(helpers.read_log_file_lines()), 2)
        # get message without datetime string and colon sign at the end of it
        msg_line = helpers.read_log_file_lines()[1]
        msg = msg_line[helpers.DATETIME_LEN+1:]
        self.assertEqual(msg, 'second loging message\n')

        # as this test creates separate log file - remove it
        try:
            # if test file is not the same as real log file - remove it
            if helpers.LOG_FILE is not self.real_log_file:
                os.remove(helpers.LOG_FILE)
        except OSError:
            pass
示例#2
0
def main(args=sys.argv[1:]):
    args = arg_parser.parse_args(args)
    # if no command is passed, invoke help
    if hasattr(args, 'func'):
        args.func(args)
    else:
        arg_parser.parse_args(['--help'])
示例#3
0
文件: tests.py 项目: scriada/timeflow
    def test_edit(self):
        subprocess.call = self.mock_subprocess
        with mock.patch.dict('os.environ', {'EDITOR': 'vim'}):
            args = parse_args(['edit'])
            args.func(args)

        with mock.patch.dict('os.environ', {'EDITOR': ''}):
            args = parse_args(['edit'])
            args.func(args)
示例#4
0
文件: tests.py 项目: scriada/timeflow
    def test_stats_last_month(self):
        date_value = datetime.datetime(2015, 2, 5)
        FakeDateTime.now = classmethod(lambda cls: date_value)

        sys.stdout = StringIO()
        args = parse_args(['stats', '--last-month'])
        args.func(args)
        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, "Work: 06h 00m\nSlack: 02h 40m")
示例#5
0
文件: tests.py 项目: scriada/timeflow
    def mock_date_and_stdout(self, args,
                             date_value=datetime.datetime(2015, 1, 1)):
        with mock.patch('timeflow.helpers.dt', FakeDateTime), \
             mock.patch('timeflow.arg_parser.dt', FakeDateTime), \
             mock.patch('timeflow.log_parser.dt', FakeDateTime):

            FakeDateTime.now = classmethod(lambda cls: date_value)

            # mock sys.stdout to evalute python's print() output
            sys.stdout = StringIO()
            args = parse_args(args)
            args.func(args)
            return sys.stdout.getvalue().strip()
示例#6
0
文件: tests.py 项目: scriada/timeflow
 def test_edit_editor(self):
     args = parse_args(['edit', '--editor', 'vim'])
示例#7
0
文件: tests.py 项目: scriada/timeflow
 def test_edit_e(self):
     subprocess.call = self.mock_subprocess
     args = parse_args(['edit', '-e', 'vim'])
     args.func(args)