Skip to content

Commit

Permalink
Merge pull request #2 from gisce/PY3_fixes
Browse files Browse the repository at this point in the history
Py3 fixes
  • Loading branch information
ecarreras authored Dec 11, 2024
2 parents 6324b1d + b2e3494 commit 4ea0083
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: GISCExFabtools

on:
push:
branches: [ git_clone_branch ]
pull_request:
branches: [ git_clone_branch ]

jobs:
run-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["2.7", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
if: matrix.python-version != '2.7'
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python 2
if: matrix.python-version == '2.7'
run: |
sudo apt update
sudo apt install python2 python-pip
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
printf '1\n' | sudo update-alternatives --config python
cd /usr/bin
sudo ln -s /usr/bin/pip2 ./pip
- name: Upgrade pip
run: |
pip install --upgrade pip setuptools wheel
- name: Install package
run: |
pip install pytest
pip install mock
pip install -e .
- name: Run test
run: |
python -m unittest discover -v
4 changes: 2 additions & 2 deletions fabtools/openvz/contextmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def put_guest(self, local_path, remote_path, use_sudo, mirror_local_mode,
# Handle modes if necessary
if (local_is_path and mirror_local_mode) or (mode is not None):
lmode = os.stat(local_path).st_mode if mirror_local_mode else mode
lmode = lmode & 07777
rmode = rattrs.st_mode & 07777
lmode = lmode & 0o7777
rmode = rattrs.st_mode & 0o7777
if lmode != rmode:
with hide('everything'):
sudo('chmod %o \"%s\"' % (lmode, remote_path))
Expand Down
4 changes: 2 additions & 2 deletions fabtools/require/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pipes import quote
from tempfile import mkstemp
from urlparse import urlparse
from six.moves.urllib_parse import urlparse
import hashlib
import os

Expand Down Expand Up @@ -191,7 +191,7 @@ def file(path=None, contents=None, source=None, url=None, md5=None,

# Ensure correct mode
if use_sudo and mode is None:
mode = oct(0666 & ~int(umask(use_sudo=True), base=8))
mode = oct(0o666 & ~int(umask(use_sudo=True), base=8))
if mode and _mode(path, use_sudo) != mode:
func('chmod %(mode)s "%(path)s"' % locals())

Expand Down
14 changes: 7 additions & 7 deletions fabtools/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@ def test_verify_remote_true(self, is_file, md5sum, put, umask, owner, mode):
used to work out whether the file is different.
"""
is_file.return_value = True
md5sum.return_value = hashlib.md5('This is a test').hexdigest()
md5sum.return_value = hashlib.md5('This is a test'.encode()).hexdigest()
self._file(contents='This is a test', verify_remote=True)
self.assertTrue(is_file.called)
self.assertTrue(md5sum.called)

def test_temp_dir(self, is_file, md5sum, put, umask, owner, mode):
owner.return_value = 'root'
umask.return_value = '0002'
mode.return_value = '0664'
umask.return_value = '{}'.format(oct(eval('0o002')))
mode.return_value = '{}'.format(oct(eval('0o664')))
from fabtools import require
require.file('/var/tmp/foo', source=__file__, use_sudo=True, temp_dir='/somewhere')
put.assert_called_with(__file__, '/var/tmp/foo', use_sudo=True, temp_dir='/somewhere')

def test_home_as_temp_dir(self, is_file, md5sum, put, umask, owner, mode):
owner.return_value = 'root'
umask.return_value = '0002'
mode.return_value = '0664'
umask.return_value = '{}'.format(oct(eval('0o002')))
mode.return_value = '{}'.format(oct(eval('0o664')))
from fabtools import require
require.file('/var/tmp/foo', source=__file__, use_sudo=True, temp_dir='')
put.assert_called_with(__file__, '/var/tmp/foo', use_sudo=True, temp_dir='')

def test_default_temp_dir(self, is_file, md5sum, put, umask, owner, mode):
owner.return_value = 'root'
umask.return_value = '0002'
mode.return_value = '0664'
umask.return_value = '{}'.format(oct(eval('0o002')))
mode.return_value = '{}'.format(oct(eval('0o664')))
from fabtools import require
require.file('/var/tmp/foo', source=__file__, use_sudo=True)
put.assert_called_with(__file__, '/var/tmp/foo', use_sudo=True, temp_dir='/tmp')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run_tests(self):
url='http://fabtools.readthedocs.org/',
license='BSD',
install_requires=[
"fabric>=1.7.0",
"fabric>=1.7.0,<2.0",
],
setup_requires=[],
tests_require=[
Expand Down

0 comments on commit 4ea0083

Please sign in to comment.