Best Python code snippet using tappy_python
test_grep.py
Source:test_grep.py  
...9    def tearDown(self):10        global lst11        lst.clear()12    def test_base_scenario(self):13        params = grep.parse_args(['aa'])14        grep.grep(self.lines, params)15        self.assertEqual(lst, ['baab'])16    def test_base_scenario_multi(self):17        params = grep.parse_args(['b'])18        grep.grep(self.lines, params)19        self.assertEqual(lst, ['baab', 'bbb'])20    def test_base_scenario_count(self):21        params = grep.parse_args(['-c', 'a'])22        grep.grep(self.lines, params)23        self.assertEqual(lst, ['1'])24    def test_base_scenario_invert(self):25        params = grep.parse_args(['-v', 'b'])26        grep.grep(self.lines, params)27        self.assertEqual(lst, ['ccc', 'A'])28    def test_base_scenario_case(self):29        params = grep.parse_args(['-i', 'a'])30        grep.grep(self.lines, params)31        self.assertEqual(lst, ['baab', 'A'])32class GrepPatternTest(TestCase):33    lines = ['baab', 'abbb', 'fc', 'AA']34    def tearDown(self):35        global lst36        lst.clear()37    def test_question_base(self):38        params = grep.parse_args(['?b'])39        grep.grep(self.lines, params)40        self.assertEqual(lst, ['baab', 'abbb'])41    def test_question_start(self):42        params = grep.parse_args(['?a'])43        grep.grep(self.lines, params)44        self.assertEqual(lst, ['baab'])45    def test_queston_end(self):46        params = grep.parse_args(['c?'])47        grep.grep(self.lines, params)48        self.assertEqual(lst, [])49    def test_queston_double(self):50        params = grep.parse_args(['b??b'])51        grep.grep(self.lines, params)52        self.assertEqual(lst, ['baab'])53    def test_queston_count(self):54        params = grep.parse_args(['???'])55        grep.grep(self.lines, params)56        self.assertEqual(lst, ['baab', 'abbb'])57    def test_asterics(self):58        params = grep.parse_args(['b*b'])59        grep.grep(self.lines, params)60        self.assertEqual(lst, ['baab', 'abbb'])61    def test_asterics_all(self):62        params = grep.parse_args(['***'])63        grep.grep(self.lines, params)64        self.assertEqual(lst, self.lines)65class GrepContextTest(TestCase):66    lines = ['vr','baab', 'abbb', 'fc', 'bbb', 'cc']67    def tearDown(self):68        global lst69        lst.clear()70    def test_context_base(self):71        params = grep.parse_args(['-C1','aa'])72        grep.grep(self.lines, params)73        self.assertEqual(lst, ['vr', 'baab', 'abbb'])74    def test_context_intersection(self):75        params = grep.parse_args(['-C1','ab'])76        grep.grep(self.lines, params)77        self.assertEqual(lst, ['vr', 'baab', 'abbb', 'fc'])78    def test_context_intersection_hard(self):79        params = grep.parse_args(['-C2','bbb'])80        grep.grep(self.lines, params)81        self.assertEqual(lst, self.lines)82    def test_before(self):83        params = grep.parse_args(['-B1','bbb'])84        grep.grep(self.lines, params)85        self.assertEqual(lst, ['baab', 'abbb', 'fc', 'bbb'])86    def test_after(self):87        params = grep.parse_args(['-A1','bbb'])88        grep.grep(self.lines, params)89        self.assertEqual(lst, ['abbb', 'fc', 'bbb', 'cc'])90class GrepLineNumbersTest(TestCase):91    lines = ['vr','baab', 'abbb', 'fc', 'bbb', 'cc']92    def tearDown(self):93        global lst94        lst.clear()95    def test_numbers_base(self):96        params = grep.parse_args(['-n','ab'])97        grep.grep(self.lines, params)98        self.assertEqual(lst, ['2:baab', '3:abbb'])99    def test_numbers_context(self):100        params = grep.parse_args(['-n', '-C1','aa'])101        grep.grep(self.lines, params)102        self.assertEqual(lst, ['1-vr', '2:baab', '3-abbb'])103    def test_numbers_context_question(self):104        params = grep.parse_args(['-n', '-C1', '???'])105        grep.grep(self.lines, params)106        self.assertEqual(lst, ['1-vr', '2:baab', '3:abbb', '4-fc', '5:bbb', '6-cc'])107class GrepBaseMyTests(TestCase):108    lines = ['baab', 'bbb', 'ccc', 'A']109    def tearDown(self):110        global lst111        lst.clear()112    def test_base1(self):113        params = grep.parse_args(['a'])114        grep.grep(self.lines, params)115        self.assertEqual(lst, ['baab'])116    def test_base2(self):117        params = grep.parse_args(['a', '-v'])118        grep.grep(self.lines, params)119        self.assertEqual(lst, ['bbb', 'ccc', 'A'])120    def test_base3(self):121        params = grep.parse_args(['a', '-i'])122        grep.grep(self.lines, params)123        self.assertEqual(lst, ['baab', 'A'])124    def test_base4(self):125        params = grep.parse_args(['a', '-i', '-v'])126        grep.grep(self.lines, params)127        self.assertEqual(lst, ['bbb', 'ccc'])128    def test_base5(self):129        params = grep.parse_args(['aa'])130        grep.grep(self.lines, params)131        self.assertEqual(lst, ['baab'])132    def test_base6(self):133        params = grep.parse_args(['aa', '-v'])134        grep.grep(self.lines, params)135        self.assertEqual(lst, ['bbb', 'ccc', 'A'])136    def test_base7(self):137        params = grep.parse_args(['aa', '-i'])138        grep.grep(self.lines, params)139        self.assertEqual(lst, ['baab'])140    def test_base8(self):141        params = grep.parse_args(['aa', '-i', '-v'])142        grep.grep(self.lines, params)143        self.assertEqual(lst, ['bbb', 'ccc', 'A'])144    def test_base9(self):145        params = grep.parse_args(['b'])146        grep.grep(self.lines, params)147        self.assertEqual(lst, ['baab', 'bbb'])148    def test_base10(self):149        params = grep.parse_args(['b', '-v'])150        grep.grep(self.lines, params)151        self.assertEqual(lst, ['ccc', 'A'])152    def test_base11(self):153        params = grep.parse_args(['b', '-i'])154        grep.grep(self.lines, params)155        self.assertEqual(lst, ['baab', 'bbb'])156    def test_base12(self):157        params = grep.parse_args(['b', '-i', '-v'])158        grep.grep(self.lines, params)159        self.assertEqual(lst, ['ccc', 'A'])160    def test_base13(self):161        params = grep.parse_args(['c'])162        grep.grep(self.lines, params)163        self.assertEqual(lst, ['ccc'])164    def test_base14(self):165        params = grep.parse_args(['c', '-v'])166        grep.grep(self.lines, params)167        self.assertEqual(lst, ['baab', 'bbb', 'A'])168    def test_base15(self):169        params = grep.parse_args(['c', '-i'])170        grep.grep(self.lines, params)171        self.assertEqual(lst, ['ccc'])172    def test_base16(self):173        params = grep.parse_args(['c', '-i', '-v'])174        grep.grep(self.lines, params)175        self.assertEqual(lst, ['baab', 'bbb', 'A'])176    def test_base17(self):177        params = grep.parse_args(['c', '-c'])178        grep.grep(self.lines, params)179        self.assertEqual(lst, ['1'])180    def test_base18(self):181        params = grep.parse_args(['c', '-c', '-i'])182        grep.grep(self.lines, params)183        self.assertEqual(lst, ['1'])184    def test_base19(self):185        params = grep.parse_args(['c', '-c', '-i', '-v'])186        grep.grep(self.lines, params)187        self.assertEqual(lst, ['3'])188    def test_base20(self):189        params = grep.parse_args(['a', '-c'])190        grep.grep(self.lines, params)191        self.assertEqual(lst, ['1'])192    def test_base21(self):193        params = grep.parse_args(['a', '-c', '-i'])194        grep.grep(self.lines, params)195        self.assertEqual(lst, ['2'])196    def test_base22(self):197        params = grep.parse_args(['a', '-c', '-i', '-v'])198        grep.grep(self.lines, params)199        self.assertEqual(lst, ['2'])200    def test_base23(self):201        params = grep.parse_args(['aa', '-c'])202        grep.grep(self.lines, params)203        self.assertEqual(lst, ['1'])204    def test_base24(self):205        params = grep.parse_args(['aa', '-c', '-i'])206        grep.grep(self.lines, params)207        self.assertEqual(lst, ['1'])208    def test_base25(self):209        params = grep.parse_args(['aa', '-c', '-i', '-v'])210        grep.grep(self.lines, params)211        self.assertEqual(lst, ['3'])212    def test_base26(self):213        params = grep.parse_args(['b', '-c'])214        grep.grep(self.lines, params)215        self.assertEqual(lst, ['2'])216    def test_base27(self):217        params = grep.parse_args(['b', '-c', '-i'])218        grep.grep(self.lines, params)219        self.assertEqual(lst, ['2'])220    def test_base28(self):221        params = grep.parse_args(['b', '-c', '-i', '-v'])222        grep.grep(self.lines, params)223        self.assertEqual(lst, ['2'])224class GrepPatternMyTests(TestCase):225    lines = ['baab', 'abbb', 'fc', 'AA']226    def tearDown(self):227        global lst228        lst.clear()229    def test_pattern1(self):230        params = grep.parse_args(['*a'])231        grep.grep(self.lines, params)232        self.assertEqual(lst, ['baab', 'abbb'])233    def test_pattern2(self):234        params = grep.parse_args(['*a', '-i'])235        grep.grep(self.lines, params)236        self.assertEqual(lst, ['baab', 'abbb', 'AA'])237    238    def test_pattern3(self):239        params = grep.parse_args(['*a', '-i', '-v'])240        grep.grep(self.lines, params)241        self.assertEqual(lst, ['fc'])242    def test_pattern4(self):243        params = grep.parse_args(['?b', '-v'])244        grep.grep(self.lines, params)245        self.assertEqual(lst, ['fc', 'AA'])246    def test_pattern5(self):247        params = grep.parse_args(['b*?b'])248        grep.grep(self.lines, params)249        self.assertEqual(lst, ['baab', 'abbb'])250    def test_pattern6(self):251        params = grep.parse_args(['????'])252        grep.grep(self.lines, params)253        self.assertEqual(lst, ['baab', 'abbb'])254    def test_pattern7(self):255        params = grep.parse_args(['????', '-v'])256        grep.grep(self.lines, params)257        self.assertEqual(lst, ['fc', 'AA'])258    def test_pattern8(self):259        params = grep.parse_args(['a*a'])260        grep.grep(self.lines, params)261        self.assertEqual(lst, ['baab'])262 263    def test_pattern9(self):264        params = grep.parse_args(['a*a', '-v'])265        grep.grep(self.lines, params)266        self.assertEqual(lst, ['abbb', 'fc', 'AA'])267class GrepContextMyTests(TestCase):268    lines = ['vr','baab', 'abbb', 'fc', 'bbb', 'cc']269    def tearDown(self):270        global lst271        lst.clear()272    def test_context1(self):273        params = grep.parse_args(['aa', '-B1'])274        grep.grep(self.lines, params)275        self.assertEqual(lst, ['vr', 'baab'])276    def test_context2(self):277        params = grep.parse_args(['aa', '-B1', '-n'])278        grep.grep(self.lines, params)279        self.assertEqual(lst, ['1-vr', '2:baab'])280    def test_context3(self):281        params = grep.parse_args(['aa', '-B1', '-n', '-v'])282        grep.grep(self.lines, params)283        self.assertEqual(lst, ['1:vr', '2-baab', '3:abbb', '4:fc', '5:bbb', '6:cc'])284    def test_context4(self):285        params = grep.parse_args(['a', '-B2'])286        grep.grep(self.lines, params)287        self.assertEqual(lst, ['vr', 'baab', 'abbb'])288    def test_context5(self):289        params = grep.parse_args(['a', '-B2', '-n'])290        grep.grep(self.lines, params)291        self.assertEqual(lst, ['1-vr', '2:baab', '3:abbb'])292    def test_context6(self):293        params = grep.parse_args(['a', '-B2', '-n', '-v'])294        grep.grep(self.lines, params)295        self.assertEqual(lst, ['1:vr', '2-baab', '3-abbb', '4:fc', '5:bbb', '6:cc'])296    def test_context7(self):297        params = grep.parse_args(['aa', '-A1'])298        grep.grep(self.lines, params)299        self.assertEqual(lst, ['baab', 'abbb'])300    def test_context8(self):301        params = grep.parse_args(['aa', '-A2'])302        grep.grep(self.lines, params)303        self.assertEqual(lst, ['baab', 'abbb', 'fc'])304    def test_context9(self):305        params = grep.parse_args(['aa', '-A1', '-n'])306        grep.grep(self.lines, params)307        self.assertEqual(lst, ['2:baab', '3-abbb'])308    def test_context10(self):309        params = grep.parse_args(['aa', '-A2', '-n'])310        grep.grep(self.lines, params)311        self.assertEqual(lst, ['2:baab', '3-abbb', '4-fc'])312    def test_context11(self):313        params = grep.parse_args(['aa', '-A1', '-n', '-v'])314        grep.grep(self.lines, params)315        self.assertEqual(lst, ['1:vr', '2-baab', '3:abbb', '4:fc', '5:bbb', '6:cc'])316class GrepContextMyTests2(TestCase):317    lines = ['vr', 'baab', 'abbb', 'fc', 'fc', 'fc', 'bbb', 'cc', 'cc', 'cc', 'cc']318    def tearDown(self):319        global lst320        lst.clear()321    def test_context2_1(self):322        params = grep.parse_args(['b', '-A1'])323        grep.grep(self.lines, params)324        self.assertEqual(lst, ['baab', 'abbb', 'fc', '--', 'bbb', 'cc'])325    def test_context2_2(self):326        params = grep.parse_args(['b', '-A1', '-v'])327        grep.grep(self.lines, params)328        self.assertEqual(lst, ['vr', 'baab', '--', 'fc', 'fc', 'fc', 'bbb', 'cc', 'cc', 'cc', 'cc'])329    def test_context2_3(self):330        params = grep.parse_args(['b', '-A2', '-n'])331        grep.grep(self.lines, params)332        self.assertEqual(lst, ['2:baab', '3:abbb', '4-fc', '5-fc', '--', '7:bbb', '8-cc', '9-cc'])333    def test_context2_4(self):334        params = grep.parse_args(['b', '-B2'])335        grep.grep(self.lines, params)336        self.assertEqual(lst, ['vr', 'baab', 'abbb', '--', 'fc', 'fc', 'bbb'])337    def test_context2_5(self):338        params = grep.parse_args(['b', '-B2', '-n'])339        grep.grep(self.lines, params)340        self.assertEqual(lst, ['1-vr', '2:baab', '3:abbb', '--', '5-fc', '6-fc', '7:bbb'])341    def test_context2_6(self):342        params = grep.parse_args(['b', '-B2', '-n', '-v'])343        grep.grep(self.lines, params)344        self.assertEqual(lst, ['1:vr', '2-baab', '3-abbb', '4:fc', '5:fc', '6:fc', '7-bbb', '8:cc', '9:cc', '10:cc', '11:cc'])345    def test_context2_7(self):346        params = grep.parse_args(['a', '-C2'])347        grep.grep(self.lines, params)348        self.assertEqual(lst, ['vr', 'baab', 'abbb', 'fc', 'fc'])349    def test_context2_8(self):350        params = grep.parse_args(['ab', '-C3', '-n'])351        grep.grep(self.lines, params)352        self.assertEqual(lst, ['1-vr', '2:baab', '3:abbb', '4-fc', '5-fc', '6-fc'])353    def test_context2_9(self):354        params = grep.parse_args(['ba', '-C2', '-n'])355        grep.grep(self.lines, params)356        self.assertEqual(lst, ['1-vr', '2:baab', '3-abbb', '4-fc'])357    def test_context2_10(self):358        params = grep.parse_args(['???', '-C1', '-n'])359        grep.grep(self.lines, params)360        self.assertEqual(lst, ['1-vr', '2:baab', '3:abbb', '4-fc', '--', '6-fc', '7:bbb', '8-cc'])361    def test_context2_11(self):362        params = grep.parse_args(['v*', '-B2', '-n'])363        grep.grep(self.lines, params)364        self.assertEqual(lst, ['1:vr'])365    def test_context2_12(self):366        params = grep.parse_args(['a??', '-C2', '-n'])367        grep.grep(self.lines, params)368        self.assertEqual(lst, ['1-vr', '2:baab', '3:abbb', '4-fc', '5-fc'])369    def test_context2_13(self):370        params = grep.parse_args(['bbb', '-C2', '-n'])371        grep.grep(self.lines, params)372        self.assertEqual(lst, ['1-vr', '2-baab', '3:abbb', '4-fc', '5-fc', '6-fc', '7:bbb', '8-cc', '9-cc'])373    def test_context2_14(self):374        params = grep.parse_args(['bbb', '-C1', '-n'])375        grep.grep(self.lines, params)376        self.assertEqual(lst, ['2-baab', '3:abbb', '4-fc', '--', '6-fc', '7:bbb', '8-cc'])377    def test_context2_15(self):378        params = grep.parse_args(['bbb', '-C1', '-n' , '-B2'])379        grep.grep(self.lines, params)380        self.assertEqual(lst, ['1-vr', '2-baab', '3:abbb', '4-fc', '5-fc', '6-fc', '7:bbb', '8-cc'])381    def test_context2_16(self):382        params = grep.parse_args(['bbb', '-C1', '-n' , '-A2'])383        grep.grep(self.lines, params)384        self.assertEqual(lst, ['2-baab', '3:abbb', '4-fc', '5-fc', '6-fc', '7:bbb', '8-cc', '9-cc'])385    def test_context2_17(self):386        params = grep.parse_args(['???', '-B1', '-n' , '-A2'])387        grep.grep(self.lines, params)...test_api.py
Source:test_api.py  
...26    cli_parser = lograptor.api.create_argument_parser()27    def setup_method(self, method):28        print("\n%s:%s" % (type(self).__name__, method.__name__))29    def test_defaults(self):30        args = self.cli_parser.parse_args([])31        assert args.after_context == 032        assert args.anonymize is False33        assert args.apps == []34        assert args.before_context == 035        assert args.cfgfiles is None36        assert args.channels == ['stdout']37        assert args.color == 'auto'38        assert args.context == 039        assert args.count is False40        assert args.exclude == []41        assert args.exclude_dir == []42        assert args.exclude_from == []43        assert args.files == []44        assert args.files_with_match is None45        assert args.filters == []46        assert args.group_separator == '--'47        assert args.hosts == []48        assert args.ignore_case is False49        assert args.include == []50        assert args.invert is False51        assert args.ip_lookup is False52        assert args.line_number is False53        assert args.loglevel == 254        assert args.matcher is None55        assert args.max_count == 056        assert args.only_matching is False57        assert args.pattern_files == []58        assert args.patterns == []59        assert args.quiet is False60        assert args.recursive is False61        assert args.report is False62        assert args.thread is False63        assert args.time_period is None64        assert args.time_range is None65        assert args.uid_lookup is False66        assert args.with_filename is None67        assert args.word is False68    def test_after_context_argument(self):69        args = self.cli_parser.parse_args('-A 10'.split())70        assert args.after_context == 1071        args = self.cli_parser.parse_args('--after-context 5'.split())72        assert args.after_context == 573    def test_anonymize_argument(self):74        args = self.cli_parser.parse_args('--anonymize'.split())75        assert args.anonymize is True76    def test_app_argument(self):77        args = self.cli_parser.parse_args('-a postfix'.split())78        assert args.apps == ['postfix']79        args = self.cli_parser.parse_args('--apps postfix,dovecot'.split())80        assert args.apps == ['postfix', 'dovecot']81    def test_before_context_argument(self):82        args = self.cli_parser.parse_args('-B 10'.split())83        assert args.before_context == 1084        args = self.cli_parser.parse_args('--before-context 5'.split())85        assert args.before_context == 586        with pytest.raises(SystemExit) as exc_info:87            self.cli_parser.parse_args('-B ten'.split())88        assert exc_info.value.args[0] == 289        with pytest.raises(SystemExit) as exc_info:90            self.cli_parser.parse_args('--before-context=-5'.split())91        assert exc_info.value.args[0] == 292        with pytest.raises(SystemExit) as exc_info:93            self.cli_parser.parse_args('--before-context 5.0'.split())94        assert exc_info.value.args[0] == 295    def test_cfgfiles_argument(self):96        args = self.cli_parser.parse_args('--conf file1'.split())97        assert args.cfgfiles == ['file1']98        args = self.cli_parser.parse_args('--conf file1 --conf file2'.split())99        assert args.cfgfiles == ['file1', 'file2']100    def test_channels_argument(self):101        args = self.cli_parser.parse_args('--output channel1'.split())102        assert args.channels == ['channel1']103        args = self.cli_parser.parse_args('--output channel1,channel2'.split())104        assert args.channels == ['channel1', 'channel2']105    def test_count_argument(self):106        args = self.cli_parser.parse_args('-c'.split())107        assert args.count is True108        args = self.cli_parser.parse_args('--count'.split())109        assert args.count is True110    def test_color_argument(self):111        args = self.cli_parser.parse_args('--color auto'.split())112        assert args.color == 'auto'113        args = self.cli_parser.parse_args('--color always'.split())114        assert args.color == 'always'115        args = self.cli_parser.parse_args('--color never'.split())116        assert args.color == 'never'117        with pytest.raises(SystemExit) as exc_info:118            self.cli_parser.parse_args('--color black'.split())119        assert exc_info.value.args[0] == 2120    def test_context_argument(self):121        args = self.cli_parser.parse_args('-C 10'.split())122        assert args.context == 10123        args = self.cli_parser.parse_args('--context 5'.split())124        assert args.context == 5125    def test_exclude_argument(self):126        args = self.cli_parser.parse_args('--exclude *.log'.split())127        assert args.exclude == ['*.log']128        args = self.cli_parser.parse_args('--exclude bar-*.log --exclude=foo.log'.split())129        assert args.exclude == ['bar-*.log', 'foo.log']130    def test_exclude_from_argument(self):131        args = self.cli_parser.parse_args('--exclude-from=foo.log'.split())132        assert args.exclude_from == ['foo.log']133        args = self.cli_parser.parse_args('--exclude-from bar.log --exclude-from=foo.log'.split())134        assert args.exclude_from == ['bar.log', 'foo.log']135    def test_exclude_dir_argument(self):136        args = self.cli_parser.parse_args('--exclude-dir=foo*/'.split())137        assert args.exclude_dir == ['foo*/']138        args = self.cli_parser.parse_args('--exclude-dir=bar/ --exclude-dir=foo'.split())139        assert args.exclude_dir == ['bar/', 'foo']140    def test_files_argument(self):141        args = self.cli_parser.parse_args('foo*.log'.split())142        assert args.files == ['foo*.log']143        args = self.cli_parser.parse_args('foo*.log bar*.log'.split())144        assert args.files == ['foo*.log', 'bar*.log']145    def test_files_with_match_argument(self):146        args = self.cli_parser.parse_args('-L'.split())147        assert args.files_with_match is False148        args = self.cli_parser.parse_args('--files-without-match'.split())149        assert args.files_with_match is False150        args = self.cli_parser.parse_args('-l'.split())151        assert args.files_with_match is True152        args = self.cli_parser.parse_args('--files-with-match'.split())153        assert args.files_with_match is True154    def test_filters_argument(self):155        args = self.cli_parser.parse_args('--filter mail=foo*'.split())156        assert args.filters == [{'mail': 'foo*'}]157        args = self.cli_parser.parse_args('-F mail=foo*,uid=bar'.split())158        assert args.filters == [{'mail': 'foo*', 'uid': 'bar'}]159        args = self.cli_parser.parse_args('-F mail=foo* -F uid=bar'.split())160        assert args.filters == [{'mail': 'foo*'}, {'uid': 'bar'}]161    def test_group_separator_argument(self):162        args = self.cli_parser.parse_args('--group-separator=---'.split())163        assert args.group_separator == '---'164        args = self.cli_parser.parse_args('--no-group-separator'.split())165        assert args.group_separator == ''166    def test_hosts_argument(self):167        args = self.cli_parser.parse_args('--hosts foo.test'.split())168        assert args.hosts == ['foo.test']169        args = self.cli_parser.parse_args('--hosts=bar.test,foo.test'.split())170        assert args.hosts == ['bar.test', 'foo.test']171    def test_ignore_case_argument(self):172        args = self.cli_parser.parse_args('-i'.split())173        assert args.ignore_case is True174        args = self.cli_parser.parse_args('--ignore-case'.split())175        assert args.ignore_case is True176    def test_include_argument(self):177        args = self.cli_parser.parse_args('--include foo*.log'.split())178        assert args.include == ['foo*.log']179        args = self.cli_parser.parse_args('--include foo*.log --include bar*.log'.split())180        assert args.include == ['foo*.log', 'bar*.log']181    def test_invert_match_argument(self):182        args = self.cli_parser.parse_args('-v'.split())183        assert args.invert is True184        args = self.cli_parser.parse_args('--invert-match'.split())185        assert args.invert is True186    def test_ip_lookup_argument(self):187        args = self.cli_parser.parse_args('--ip-lookup'.split())188        assert args.ip_lookup is True189    def test_line_number_argument(self):190        args = self.cli_parser.parse_args('-n'.split())191        assert args.line_number is True192        args = self.cli_parser.parse_args('--line-number'.split())193        assert args.line_number is True194    def test_loglevel_argument(self):195        args = self.cli_parser.parse_args('-d 4'.split())196        assert args.loglevel == 4197        with pytest.raises(SystemExit) as exc_info:198            self.cli_parser.parse_args('-d 5'.split())199        assert exc_info.value.args[0] == 2200    def test_matcher_argument(self):201        args = self.cli_parser.parse_args('-G'.split())202        assert args.matcher == '--ruled'203        args = self.cli_parser.parse_args('--ruled'.split())204        assert args.matcher == '--ruled'205        args = self.cli_parser.parse_args('-X'.split())206        assert args.matcher == '--unruled'207        args = self.cli_parser.parse_args('--unruled'.split())208        assert args.matcher == '--unruled'209        args = self.cli_parser.parse_args('-U'.split())210        assert args.matcher == '--unparsed'211        args = self.cli_parser.parse_args('--unparsed'.split())212        assert args.matcher == '--unparsed'213    def test_max_count_argument(self):214        args = self.cli_parser.parse_args('-m 3'.split())215        assert args.max_count == 3216        args = self.cli_parser.parse_args('--max-count 1'.split())217        assert args.max_count == 1218    def test_only_matching_argument(self):219        args = self.cli_parser.parse_args('-o'.split())220        assert args.only_matching is True221        args = self.cli_parser.parse_args('--only-matching'.split())222        assert args.only_matching is True223    def test_pattern_files_argument(self):224        args = self.cli_parser.parse_args('-f patterns.txt'.split())225        assert args.pattern_files == ['patterns.txt']226        args = self.cli_parser.parse_args('-f patterns1.txt --file=patterns2.txt'.split())227        assert args.pattern_files == ['patterns1.txt', 'patterns2.txt']228    def test_patterns_argument(self):229        args = self.cli_parser.parse_args('-e .*'.split())230        assert args.patterns == ['.*']231        args = self.cli_parser.parse_args('-e .* -e ^$'.split())232        assert args.patterns == ['.*', '^$']233        args = self.cli_parser.parse_args('--regexp=.* -e ^$'.split())234        assert args.patterns == ['.*', '^$']235        args = self.cli_parser.parse_args('--regexp=.* -e ^$'.split())236        assert args.patterns == ['.*', '^$']237    def test_quiet_argument(self):238        args = self.cli_parser.parse_args('-q'.split())239        assert args.quiet is True240        args = self.cli_parser.parse_args('--quiet'.split())241        assert args.quiet is True242    def test_recursive_argument(self):243        args = self.cli_parser.parse_args('-r'.split())244        assert args.recursive is True245        args = self.cli_parser.parse_args('--recursive'.split())246        assert args.recursive is True247    def test_report_argument(self):248        args = self.cli_parser.parse_args('--report foo.txt'.split())249        assert args.report == 'foo.txt'250    def test_thread_argument(self):251        args = self.cli_parser.parse_args('-T'.split())252        assert args.thread is True253        args = self.cli_parser.parse_args('--thread'.split())254        assert args.thread is True255    def test_time_period_argument(self):256        year = datetime.datetime.now().year257        args = self.cli_parser.parse_args('--date=0825,0826'.split())258        assert args.time_period == (datetime.datetime(year, 8, 25, 0, 0),259                                    datetime.datetime(year, 8, 26, 23, 59, 59))260        dt = datetime.datetime.now().replace(microsecond=0)261        args = self.cli_parser.parse_args('--last day'.split())262        assert args.time_period == (dt - datetime.timedelta(days=1),263                                    dt + datetime.timedelta(hours=1))264    def test_time_range_argument(self):265        args = self.cli_parser.parse_args('--time 10:00,14:30'.split())266        assert args.time_range.h1 == 10267        assert args.time_range.m1 == 0268        assert args.time_range.h2 == 14269        assert args.time_range.m2 == 30270    def test_uid_lookup_argument(self):271        args = self.cli_parser.parse_args('--uid-lookup'.split())272        assert args.uid_lookup is True273    def test_with_filename_argument(self):274        args = self.cli_parser.parse_args('-H'.split())275        assert args.with_filename is True276        args = self.cli_parser.parse_args('--with-filename'.split())277        assert args.with_filename is True278        args = self.cli_parser.parse_args('-h'.split())279        assert args.with_filename is False280        args = self.cli_parser.parse_args('--no-filename'.split())281        assert args.with_filename is False282    def test_word_argument(self):283        args = self.cli_parser.parse_args('-w'.split())284        assert args.word is True285        args = self.cli_parser.parse_args('--word-regex'.split())...test_variable_command.py
Source:test_variable_command.py  
...36    def tearDown(self):37        clear_db_variables()38    def test_variables_set(self):39        """Test variable_set command"""40        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'foo', 'bar']))41        self.assertIsNotNone(Variable.get("foo"))42        self.assertRaises(KeyError, Variable.get, "foo1")43    def test_variables_get(self):44        Variable.set('foo', {'foo': 'bar'}, serialize_json=True)45        with redirect_stdout(io.StringIO()) as stdout:46            variable_command.variables_get(self.parser.parse_args(['variables', 'get', 'foo']))47            self.assertEqual('{\n  "foo": "bar"\n}\n', stdout.getvalue())48    def test_get_variable_default_value(self):49        with redirect_stdout(io.StringIO()) as stdout:50            variable_command.variables_get(51                self.parser.parse_args(['variables', 'get', 'baz', '--default', 'bar'])52            )53            self.assertEqual("bar\n", stdout.getvalue())54    def test_get_variable_missing_variable(self):55        with self.assertRaises(SystemExit):56            variable_command.variables_get(self.parser.parse_args(['variables', 'get', 'no-existing-VAR']))57    def test_variables_set_different_types(self):58        """Test storage of various data types"""59        # Set a dict60        variable_command.variables_set(61            self.parser.parse_args(['variables', 'set', 'dict', '{"foo": "oops"}'])62        )63        # Set a list64        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'list', '["oops"]']))65        # Set str66        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'str', 'hello string']))67        # Set int68        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'int', '42']))69        # Set float70        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'float', '42.0']))71        # Set true72        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'true', 'true']))73        # Set false74        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'false', 'false']))75        # Set none76        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'null', 'null']))77        # Export and then import78        variable_command.variables_export(79            self.parser.parse_args(['variables', 'export', 'variables_types.json'])80        )81        variable_command.variables_import(82            self.parser.parse_args(['variables', 'import', 'variables_types.json'])83        )84        # Assert value85        self.assertEqual({'foo': 'oops'}, Variable.get('dict', deserialize_json=True))86        self.assertEqual(['oops'], Variable.get('list', deserialize_json=True))87        self.assertEqual('hello string', Variable.get('str'))  # cannot json.loads(str)88        self.assertEqual(42, Variable.get('int', deserialize_json=True))89        self.assertEqual(42.0, Variable.get('float', deserialize_json=True))90        self.assertEqual(True, Variable.get('true', deserialize_json=True))91        self.assertEqual(False, Variable.get('false', deserialize_json=True))92        self.assertEqual(None, Variable.get('null', deserialize_json=True))93        os.remove('variables_types.json')94    def test_variables_list(self):95        """Test variable_list command"""96        # Test command is received97        variable_command.variables_list(self.parser.parse_args(['variables', 'list']))98    def test_variables_delete(self):99        """Test variable_delete command"""100        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'foo', 'bar']))101        variable_command.variables_delete(self.parser.parse_args(['variables', 'delete', 'foo']))102        self.assertRaises(KeyError, Variable.get, "foo")103    def test_variables_import(self):104        """Test variables_import command"""105        with self.assertRaisesRegex(SystemExit, r"Invalid variables file"):106            variable_command.variables_import(self.parser.parse_args(['variables', 'import', os.devnull]))107    def test_variables_export(self):108        """Test variables_export command"""109        variable_command.variables_export(self.parser.parse_args(['variables', 'export', os.devnull]))110    def test_variables_isolation(self):111        """Test isolation of variables"""112        tmp1 = tempfile.NamedTemporaryFile(delete=True)113        tmp2 = tempfile.NamedTemporaryFile(delete=True)114        # First export115        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'foo', '{"foo":"bar"}']))116        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'bar', 'original']))117        variable_command.variables_export(self.parser.parse_args(['variables', 'export', tmp1.name]))118        first_exp = open(tmp1.name)119        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'bar', 'updated']))120        variable_command.variables_set(self.parser.parse_args(['variables', 'set', 'foo', '{"foo":"oops"}']))121        variable_command.variables_delete(self.parser.parse_args(['variables', 'delete', 'foo']))122        variable_command.variables_import(self.parser.parse_args(['variables', 'import', tmp1.name]))123        self.assertEqual('original', Variable.get('bar'))124        self.assertEqual('{\n  "foo": "bar"\n}', Variable.get('foo'))125        # Second export126        variable_command.variables_export(self.parser.parse_args(['variables', 'export', tmp2.name]))127        second_exp = open(tmp2.name)128        self.assertEqual(first_exp.read(), second_exp.read())129        # Clean up files130        second_exp.close()...test_cli.py
Source:test_cli.py  
2from mock import patch3from lesspass.cli import parse_args4class TestParseArgs(unittest.TestCase):5    def test_parse_args_site(self):6        self.assertEqual(parse_args(["site"]).site, "site")7    def test_parse_args_login(self):8        self.assertEqual(parse_args(["site", "login"]).login, "login")9    def test_parse_args_LESSPASS_MASTER_PASSWORD_env_variable(self):10        with patch.dict("os.environ", {"LESSPASS_MASTER_PASSWORD": "password"}):11            self.assertEqual(parse_args([]).master_password, "password")12    def test_parse_args_master_password(self):13        self.assertEqual(14            parse_args(["site", "login", "masterpassword"]).master_password,15            "masterpassword",16        )17    def test_parse_args_l(self):18        self.assertTrue(parse_args(["site", "-l"]).l)19        self.assertTrue(parse_args(["site", "--lowercase"]).l)20    def test_parse_args_u(self):21        self.assertTrue(parse_args(["site", "-u"]).u)22        self.assertTrue(parse_args(["site", "--uppercase"]).u)23    def test_parse_args_d(self):24        self.assertTrue(parse_args(["site", "-d"]).d)25        self.assertTrue(parse_args(["site", "--digits"]).d)26    def test_parse_args_s(self):27        self.assertTrue(parse_args(["site", "-s"]).s)28        self.assertTrue(parse_args(["site", "--symbols"]).s)29    def test_parse_args_lu(self):30        args = parse_args(["site", "-lu"])31        self.assertTrue(args.l)32        self.assertTrue(args.u)33        self.assertFalse(args.d)34        self.assertFalse(args.s)35    def test_parse_args_lud(self):36        args = parse_args(["site", "-lud"])37        self.assertTrue(args.l)38        self.assertTrue(args.u)39        self.assertTrue(args.d)40        self.assertFalse(args.s)41    def test_parse_args_luds(self):42        args = parse_args(["site", "-luds"])43        self.assertTrue(args.l)44        self.assertTrue(args.u)45        self.assertTrue(args.d)46        self.assertTrue(args.s)47    def test_parse_args_no_lowercase(self):48        self.assertTrue(parse_args(["site", "--no-lowercase"]).nl)49    def test_parse_args_no_uppercase(self):50        self.assertTrue(parse_args(["site", "--no-uppercase"]).nu)51    def test_parse_args_no_digits(self):52        self.assertTrue(parse_args(["site", "--no-digits"]).nd)53    def test_parse_args_no_symbols(self):54        self.assertTrue(parse_args(["site", "--no-symbols"]).ns)55    def test_parse_args_length_default(self):56        self.assertEqual(parse_args(["site"]).length, 16)57    def test_parse_args_length_long(self):58        self.assertEqual(parse_args(["site", "--length", "8"]).length, 8)59    def test_parse_args_length_short(self):60        self.assertEqual(parse_args(["site", "-L6"]).length, 6)61        self.assertEqual(parse_args(["site", "-L", "12"]).length, 12)62    def test_parse_args_counter_default(self):63        self.assertEqual(parse_args(["site"]).counter, 1)64    def test_parse_args_counter_long(self):65        self.assertEqual(parse_args(["site", "--counter", "2"]).counter, 2)66    def test_parse_args_counter_short(self):67        self.assertEqual(parse_args(["site", "-C99"]).counter, 99)68        self.assertEqual(parse_args(["site", "-C", "100"]).counter, 100)69    def test_parse_args_clipboard_default(self):70        self.assertFalse(parse_args(["site"]).clipboard)71    def test_parse_args_clipboard_long(self):72        self.assertTrue(parse_args(["site", "--copy"]).clipboard)73    def test_parse_args_clipboard_short(self):74        self.assertTrue(parse_args(["site", "-c"]).clipboard)75    def test_parse_args_prompt_long(self):76        self.assertTrue(parse_args(["--prompt"]).prompt)77    def test_parse_args_prompt_short(self):78        self.assertTrue(parse_args(["-p"]).prompt)79    def test_parse_args_exclude_default(self):80        self.assertEqual(parse_args(["site"]).exclude, None)81    def test_parse_args_exclude(self):82        self.assertEqual(parse_args(["site", "--exclude", "!@$*+-"]).exclude, "!@$*+-")83    def test_parse_args_exclude_single_and_double_quote(self):84        self.assertEqual(parse_args(["site", "--exclude", "\"'"]).exclude, "\"'")85    def test_parse_no_fingerprint(self):86        self.assertTrue(parse_args(["site", "--no-fingerprint"]).no_fingerprint)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
