diff --git a/.github/workflows/test-macOS-sur.yml b/.github/workflows/test-macOS-sur.yml new file mode 100644 index 0000000..ec3ae50 --- /dev/null +++ b/.github/workflows/test-macOS-sur.yml @@ -0,0 +1,32 @@ +name: MacOS (SUR) + +on: + push: + schedule: + - cron: '0 8 * * *' + +jobs: + run-tests: + name: Python ${{ matrix.python-version }} + runs-on: macOS-11 + strategy: + max-parallel: 9 + fail-fast: false + matrix: + python-version: [3.7, 3.9] + + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dev dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + + - name: Test with pytest + run: | + pytest pyderman/test.py diff --git a/.github/workflows/test-macOS.yml b/.github/workflows/test-macOS.yml index b64d669..469b9f8 100644 --- a/.github/workflows/test-macOS.yml +++ b/.github/workflows/test-macOS.yml @@ -8,7 +8,7 @@ on: jobs: run-tests: name: Python ${{ matrix.python-version }} - runs-on: macOS-latest + runs-on: macOS-10.15 strategy: max-parallel: 9 fail-fast: false diff --git a/pyderman/__init__.py b/pyderman/__init__.py index 53e6fee..9c65f48 100644 --- a/pyderman/__init__.py +++ b/pyderman/__init__.py @@ -7,7 +7,7 @@ import tarfile from pyderman import drivers from pyderman.util import downloader -from pyderman.drivers import all_drivers, chrome, firefox, opera, phantomjs +from pyderman.drivers import all_drivers, chrome, firefox, opera, phantomjs, edge _versions = sorted(['32', '64'], key=lambda _v: not platform.machine().endswith(_v)) @@ -19,6 +19,8 @@ if _o[0] in platform.system().lower(): _current_os = _o[1] _ext = _o[2] +if _current_os == 'mac' and int(platform.release().split('.')[0]) >= 20: + _current_os = 'mac-sur' def install(browser=None, file_directory='./lib/', verbose=True, chmod=True, overwrite=False, version='latest', filename=None, return_info=False): diff --git a/pyderman/drivers/chrome.py b/pyderman/drivers/chrome.py index 55eb714..bad6dce 100644 --- a/pyderman/drivers/chrome.py +++ b/pyderman/drivers/chrome.py @@ -9,6 +9,9 @@ def get_url(version='latest', _os=None, _os_bit=None): version = downloader.raw(_base_version) if not version: raise Exception("Unable to locate latest ChromeDriver version!") + if _os == 'mac-sur': + _os = 'mac' # chromedriver_mac64_m1 + _os_bit = _os_bit + '_m1' download = _base_download % (version, _os, _os_bit) return 'chromedriver', download, version diff --git a/pyderman/drivers/firefox.py b/pyderman/drivers/firefox.py index 0e52692..ab4ed73 100644 --- a/pyderman/drivers/firefox.py +++ b/pyderman/drivers/firefox.py @@ -5,7 +5,9 @@ def get_url(version='latest', _os=None, _os_bit=None): urls = github.find_links('mozilla', 'geckodriver', version) for u in urls: - target = '%s%s' % (_os, _os_bit) if _os != 'mac' else 'macos' + target = '%s%s.' % (_os, _os_bit) if _os != 'mac' else 'macos.' + if _os == 'mac-sur': + target = 'macos-aarch64.' if target in u: ver = re.search(r'v(\d{1,2}\.\d{1,2}\.\d{1,2})', u).group(1) return 'geckodriver', u, ver diff --git a/pyderman/test.py b/pyderman/test.py index be84c61..f6d27f9 100644 --- a/pyderman/test.py +++ b/pyderman/test.py @@ -1,32 +1,54 @@ import os -from pyderman import install, all_drivers +from pyderman import install, chrome, firefox, opera, phantomjs, edge import subprocess import unittest +import platform + + +def process_driver(driver, self): + print("Testing %s..." % driver.__name__) + try: + data = install(browser=driver, verbose=True, chmod=True, overwrite=True, return_info=True) + except OSError as err: + print(err) + return # OSError is raised if the given OS cannot support the driver, which we need to ignore. + path = data['path'] + if not os.path.exists(path): + raise FileNotFoundError('The %s executable was not properly downloaded.' % driver.__name__) + output = subprocess.check_output([path, '--version']).decode('utf-8') + print('Version:', output) + self.assertIn( + data['version'], + output.lower(), + msg="Driver %s did not output proper version! ('%s')" % (driver.__name__, data['version']) + ) + print('%s is installed at: "%s"' % (data['driver'], path)) + print('\n\n\n') class TestDriverInstalls(unittest.TestCase): - def test_all_installs(self): - for driver in all_drivers: - print("Testing %s..." % driver.__name__) - try: - data = install(browser=driver, verbose=True, chmod=True, overwrite=True, return_info=True) - except OSError as err: - print(err) - continue # OSError is raised if the given OS cannot support the driver, which we need to ignore. - path = data['path'] - if not os.path.exists(path): - raise FileNotFoundError('The %s executable was not properly downloaded.' % driver.__name__) - output = subprocess.check_output([path, '--version']).decode('utf-8') - print('Version:', output) - self.assertIn( - data['version'], - output.lower(), - msg="Driver %s did not output proper version! ('%s')" % (driver.__name__, data['version']) - ) - print('%s is installed at: "%s"' % (data['driver'], path)) - print('\n\n\n') + def test_details(self): + print('Machine:', platform.machine()) + print('Platform:', platform.platform()) + print('Arch:', platform.architecture()) + print('Processor:', platform.processor()) + print('Release:', platform.release()) + + def test_chrome(self): + process_driver(chrome, self) + + def test_firefox(self): + process_driver(firefox, self) + + def test_opera(self): + process_driver(opera, self) + + def test_phantomjs(self): + process_driver(phantomjs, self) + def test_edge(self): + process_driver(edge, self) if __name__ == "__main__": unittest.main()