How to use watchers method in uiautomator

Best Python code snippet using uiautomator

watchlists_unittest.py

Source:watchlists_unittest.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright (c) 2011 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5"""Unit tests for watchlists.py."""6# pylint: disable=E1103,no-value-for-parameter,protected-access7import os8import sys9import unittest10sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))11from third_party import mock12import watchlists13class WatchlistsTest(unittest.TestCase):14 def setUp(self):15 super(WatchlistsTest, self).setUp()16 mock.patch('watchlists.Watchlists._HasWatchlistsFile').start()17 mock.patch('watchlists.Watchlists._ContentsOfWatchlistsFile').start()18 mock.patch('watchlists.logging.error').start()19 self.addCleanup(mock.patch.stopall)20 def testMissingWatchlistsFileOK(self):21 """Test that we act gracefully if WATCHLISTS file is missing."""22 watchlists.Watchlists._HasWatchlistsFile.return_value = False23 wl = watchlists.Watchlists('/some/random/path')24 self.assertEqual(wl.GetWatchersForPaths(['some_path']), [])25 def testGarbledWatchlistsFileOK(self):26 """Test that we act gracefully if WATCHLISTS file is garbled."""27 contents = 'some garbled and unwanted text'28 watchlists.Watchlists._HasWatchlistsFile.return_value = True29 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents30 wl = watchlists.Watchlists('/a/path')31 self.assertEqual(wl.GetWatchersForPaths(['some_path']), [])32 def testNoWatchers(self):33 contents = \34 """{35 'WATCHLIST_DEFINITIONS': {36 'a_module': {37 'filepath': 'a_module',38 },39 },40 'WATCHLISTS': {41 'a_module': [],42 },43 } """44 watchlists.Watchlists._HasWatchlistsFile.return_value = True45 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents46 wl = watchlists.Watchlists('/a/path')47 self.assertEqual(wl.GetWatchersForPaths(['a_module']), [])48 def testValidWatcher(self):49 watchers = ['abc@def.com', 'x1@xyz.org']50 contents = \51 """{52 'WATCHLIST_DEFINITIONS': {53 'a_module': {54 'filepath': 'a_module',55 },56 },57 'WATCHLISTS': {58 'a_module': %s,59 },60 } """ % watchers61 watchlists.Watchlists._HasWatchlistsFile.return_value = True62 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents63 wl = watchlists.Watchlists('/a/path')64 self.assertEqual(wl.GetWatchersForPaths(['a_module']), watchers)65 def testMultipleWatchlistsTrigger(self):66 """Test that multiple watchlists can get triggered for one filepath."""67 contents = \68 """{69 'WATCHLIST_DEFINITIONS': {70 'mac': {71 'filepath': 'mac',72 },73 'views': {74 'filepath': 'views',75 },76 },77 'WATCHLISTS': {78 'mac': ['x1@chromium.org'],79 'views': ['x2@chromium.org'],80 },81 } """82 watchlists.Watchlists._HasWatchlistsFile.return_value = True83 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents84 wl = watchlists.Watchlists('/a/path')85 self.assertEqual(wl.GetWatchersForPaths(['file_views_mac']),86 ['x1@chromium.org', 'x2@chromium.org'])87 def testDuplicateWatchers(self):88 """Test that multiple watchlists can get triggered for one filepath."""89 watchers = ['someone@chromium.org']90 contents = \91 """{92 'WATCHLIST_DEFINITIONS': {93 'mac': {94 'filepath': 'mac',95 },96 'views': {97 'filepath': 'views',98 },99 },100 'WATCHLISTS': {101 'mac': %s,102 'views': %s,103 },104 } """ % (watchers, watchers)105 watchlists.Watchlists._HasWatchlistsFile.return_value = True106 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents107 wl = watchlists.Watchlists('/a/path')108 self.assertEqual(wl.GetWatchersForPaths(['file_views_mac']), watchers)109 def testWinPathWatchers(self):110 """Test watchers for a windows path (containing backward slashes)."""111 watchers = ['abc@def.com', 'x1@xyz.org']112 contents = \113 """{114 'WATCHLIST_DEFINITIONS': {115 'browser': {116 'filepath': 'chrome/browser/.*',117 },118 },119 'WATCHLISTS': {120 'browser': %s,121 },122 } """ % watchers123 saved_sep = watchlists.os.sep124 watchlists.os.sep = '\\' # to pose as win32125 watchlists.Watchlists._HasWatchlistsFile.return_value = True126 watchlists.Watchlists._ContentsOfWatchlistsFile.return_value = contents127 wl = watchlists.Watchlists(r'a\path')128 returned_watchers = wl.GetWatchersForPaths(129 [r'chrome\browser\renderer_host\render_widget_host.h'])130 watchlists.os.sep = saved_sep # revert back os.sep before asserts131 self.assertEqual(returned_watchers, watchers)132if __name__ == '__main__':133 import unittest...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run uiautomator automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful