Skip to content

Commit

Permalink
Fix macOS. (#11)
Browse files Browse the repository at this point in the history
* Debug Mac OS changes.
  • Loading branch information
shadowmoose committed Aug 20, 2021
1 parent 02de4f8 commit 0c85b5e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 24 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test-macOS-sur.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/test-macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pyderman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions pyderman/drivers/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion pyderman/drivers/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 43 additions & 21 deletions pyderman/test.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 0c85b5e

Please sign in to comment.