Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from ConfigParser import ConfigParser
- class FileFinder:
- def file_finder(self, path, mask):
- files = []
- for root, dirs, filenames in os.walk(path):
- for f in filenames:
- if mask in f:
- files.append(f)
- return files
- class GetLocators:
- result = None
- def parse_config(self, loc_files):
- result = dict()
- parser = ConfigParser()
- parser.read(loc_files)
- for section in parser.sections():
- result[section] = {'type': parser.get(section, 'type'), 'value': parser.get(section, 'value')}
- locators = result.keys()
- return locators
- class CheckLocatorInFile:
- def check_locator_in_file(self, locators, py_files):
- for py_file in py_files:
- with open(py_file, 'r') as inF:
- for line in inF:
- for locator in locators:
- if locator in line:
- locators.remove(locator)
- print locators
- return locators
- class CheckUnusedLocators:
- ff = FileFinder()
- gl = GetLocators()
- cl = CheckLocatorInFile()
- def check_unused_locators(self):
- # get python files from script dir
- py_files_dir = os.getcwd()
- mask = '.py'
- py_files = self.ff.file_finder(py_files_dir, mask)
- py_files = [py_file for py_file in py_files if str(py_file).endswith('.py')]
- # get locators list
- loc_files_dir = str(py_files_dir) + '/config'
- mask = 'selectors'
- loc_files = self.ff.file_finder(loc_files_dir, mask)
- new_loc_files = []
- for lc in loc_files:
- lc = './config/' + str(lc)
- new_loc_files.append(lc)
- locators = self.gl.parse_config(new_loc_files)
- # check if locator is in file
- result = self.cl.check_locator_in_file(locators, py_files)
- if result:
- for r in result:
- print 'We have unused locators: {locator}'.format(locator=r)
- cu = CheckUnusedLocators()
- cu.check_unused_locators()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement