1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3############################################################################### 4# 5# Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez. 6# 7# Permission is hereby granted, free of charge, to any person obtaining a copy 8# of this software and associated documentation files (the "Software"), to deal 9# in the Software without restriction, including without limitation the rights 10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11# copies of the Software, and to permit persons to whom the Software is 12# furnished to do so, subject to the following conditions: 13# 14# The above copyright notice and this permission notice shall be included 15# in all copies or substantial portions of the Software. 16# 17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23# SOFTWARE. 24# 25# https://www.opensource.org/licenses/mit-license.php 26# 27############################################################################### 28 29import sys 30import os 31import re 32import unittest 33import operator 34 35# Ensure python finds the local simpletap module 36sys.path.append(os.path.dirname(os.path.abspath(__file__))) 37 38from basetest import Task, TestCase 39 40 41class TestVerbosity(TestCase): 42 def setUp(self): 43 self.t = Task() 44 self.t.config("print.empty.columns", "1") 45 46 self.t("add Sample") 47 48 # TODO Verbosity: 'edit' 49 50 def test_verbosity_new_id(self): 51 """Verbosity new-id""" 52 code, out, err = self.t("rc.verbose:new-id add Sample1") 53 self.assertRegex(out, r"Created task \d") 54 55 code, out, err = self.t("rc.verbose:nothing add Sample2") 56 self.assertNotRegex(out, r"Created task \d") 57 58 def test_verbosity_new_uuid(self): 59 """Verbosity new-uuid""" 60 code, out, err = self.t(("rc.verbose:new-uuid", "add", "Sample1")) 61 self.assertRegex(out, r"Created task [0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}") 62 63 def test_verbosity_label(self): 64 """Verbosity label""" 65 code, out, err = self.t("rc.verbose:label ls") 66 self.assertRegex( 67 out, 68 "ID.+A.+D.+Project.+Tags.+R.+Wait.+S.+Due.+Until.+Description" 69 ) 70 71 def test_verbosity_affected(self): 72 """Verbosity affected""" 73 code, out, err = self.t("rc.verbose:affected ls") 74 75 expected = re.compile(r"^\d+ tasks?$", re.MULTILINE) 76 self.assertRegex(out, expected) 77 78 def test_verbosity_off(self): 79 """Verbosity off""" 80 code, out, err = self.t("rc.verbose:nothing ls") 81 82 expected = re.compile(r"^\d+ tasks?$", re.MULTILINE) 83 self.assertNotRegex(out, expected) 84 self.assertNotRegex(out, "ID.+Project.+Pri.+Description") 85 86 def test_verbosity_special(self): 87 """Verbosity special""" 88 code, out, err = self.t("rc.verbose:special 1 mod +next") 89 90 self.assertIn("The 'next' special tag will boost the urgency of this " 91 "task so it appears on the 'next' report.", out) 92 93 def test_verbosity_blank(self): 94 """Verbosity blank""" 95 96 def count_blank_lines(x): 97 return x.splitlines().count('') 98 99 code, out, err = self.t("rc.verbose:nothing ls") 100 self.assertEqual(count_blank_lines(out), 0) 101 102 code, out, err = self.t("rc.verbose:blank ls") 103 self.assertEqual(count_blank_lines(out), 2) 104 105 def test_verbosity_header(self): 106 """Verbosity header""" 107 108 code, out, err = self.t("rc.verbose:override ls") 109 self.assertNotIn("TASKRC override:", err) 110 self.assertNotIn("TASKDATA override:", err) 111 112 code, out, err = self.t("rc.verbose:header,override ls") 113 self.assertIn("TASKRC override:", err) 114 self.assertIn("TASKDATA override:", err) 115 116 def test_verbosity_project(self): 117 """Verbosity project""" 118 119 code, out, err = self.t("rc.verbose:nothing add proj:T one") 120 self.assertNotIn("The project 'T' has changed.", err) 121 122 code, out, err = self.t("rc.verbose:project add proj:T two") 123 self.assertIn("The project 'T' has changed.", err) 124 125 def test_bug_2247(self): 126 """ 127 Verbosity override is applied regardless of the order of the arguments. 128 """ 129 130 code, out, err = self.t("rc.color:0 add test") 131 self.assertIn("Configuration override", err) 132 133 # Once rc.verbose:nothing is set, no output about configuration overrides should appear 134 code, out, err = self.t("rc.verbose:nothing add test") 135 self.assertNotIn("Configuration override", err) 136 137 code, out, err = self.t("rc.color:0 rc.verbose:nothing add test") 138 self.assertNotIn("Configuration override", err) 139 140 code, out, err = self.t("rc.verbose:nothing rc.color:0 add test") 141 self.assertNotIn("Configuration override", err) 142 143 144if __name__ == "__main__": 145 from simpletap import TAPTestRunner 146 unittest.main(testRunner=TAPTestRunner()) 147 148# vim: ai sts=4 et sw=4 ft=python 149