commit
f10463a97c
60
.github/workflows/tests.yaml
vendored
Normal file
60
.github/workflows/tests.yaml
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
name: Pubs tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 8 * * *'
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit-test:
|
||||||
|
name: Run unit tests
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest, ubuntu-latest]
|
||||||
|
python-version: [3.6, 3.7, 3.8, 3.9]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r dev_requirements.txt
|
||||||
|
- name: Configure git author (fix issue with environment variable)
|
||||||
|
run: |
|
||||||
|
# Manually sets some git user and email to avoid failure of the test
|
||||||
|
# (For some reason the environment variables set in the test are not
|
||||||
|
# taken into account by git on the runner.)
|
||||||
|
git config --global user.name "Pubs test"
|
||||||
|
git config --global user.email "unittest@pubs.org"
|
||||||
|
- name: Test with pytest (mock API mode)
|
||||||
|
env:
|
||||||
|
PUBS_TESTS_MODE: MOCK
|
||||||
|
run: pytest
|
||||||
|
- name: Test with pytest (online API mode)
|
||||||
|
env:
|
||||||
|
PUBS_TESTS_MODE: COLLECT
|
||||||
|
run: pytest
|
||||||
|
|
||||||
|
install-test:
|
||||||
|
name: Test installation
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest, ubuntu-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
if: github.event_name == 'schedule'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
- name: install test
|
||||||
|
run: |
|
||||||
|
pip install -U pip
|
||||||
|
pip install pubs
|
||||||
|
pubs --help
|
||||||
|
pip uninstall -y pubs
|
89
.travis.yml
89
.travis.yml
@ -1,89 +0,0 @@
|
|||||||
# list of environments to test
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
|
|
||||||
# Full tests (with online API)
|
|
||||||
- os: linux
|
|
||||||
language: python
|
|
||||||
python: 3.9
|
|
||||||
dist: xenial
|
|
||||||
sudo: true
|
|
||||||
env:
|
|
||||||
- TO_TEST=TEST_FULL
|
|
||||||
- os: osx
|
|
||||||
language: generic
|
|
||||||
python: ">=3.6"
|
|
||||||
env:
|
|
||||||
- TO_TEST=TEST_FULL
|
|
||||||
before_install:
|
|
||||||
- brew outdated python3 || brew install python3 || brew upgrade python3
|
|
||||||
- python3 -m venv env
|
|
||||||
- source env/bin/activate
|
|
||||||
|
|
||||||
# Mock tests (with mock API)
|
|
||||||
- os: linux
|
|
||||||
language: python
|
|
||||||
python: 3.6
|
|
||||||
env:
|
|
||||||
- TO_TEST=TEST_MOCK
|
|
||||||
- os: linux
|
|
||||||
language: python
|
|
||||||
dist: xenial
|
|
||||||
python: 3.7
|
|
||||||
sudo: true
|
|
||||||
env:
|
|
||||||
- TO_TEST=TEST_MOCK
|
|
||||||
- os: linux
|
|
||||||
language: python
|
|
||||||
dist: xenial
|
|
||||||
python: 3.8
|
|
||||||
sudo: true
|
|
||||||
env:
|
|
||||||
- TO_TEST=TEST_MOCK
|
|
||||||
- os: linux
|
|
||||||
language: python
|
|
||||||
dist: xenial
|
|
||||||
python: 3.9
|
|
||||||
sudo: true
|
|
||||||
env:
|
|
||||||
- TO_TEST=TEST_MOCK
|
|
||||||
|
|
||||||
|
|
||||||
# Install tests
|
|
||||||
- os: linux
|
|
||||||
language: python
|
|
||||||
python: 2.7
|
|
||||||
env:
|
|
||||||
- TO_TEST=INSTALL
|
|
||||||
if: type = cron
|
|
||||||
- os: linux
|
|
||||||
language: python
|
|
||||||
dist: xenial
|
|
||||||
sudo: true
|
|
||||||
python: 3.9
|
|
||||||
env:
|
|
||||||
- TO_TEST=INSTALL
|
|
||||||
if: type = cron
|
|
||||||
- os: osx
|
|
||||||
language: generic
|
|
||||||
python: 2.7
|
|
||||||
env:
|
|
||||||
- TO_TEST=INSTALL
|
|
||||||
if: type = cron
|
|
||||||
- os: osx
|
|
||||||
language: generic
|
|
||||||
python: ">=3.6"
|
|
||||||
env:
|
|
||||||
- TO_TEST=INSTALL
|
|
||||||
if: type = cron
|
|
||||||
|
|
||||||
allow_failures:
|
|
||||||
- python: 2.7
|
|
||||||
|
|
||||||
# command to run tests
|
|
||||||
script:
|
|
||||||
- python --version
|
|
||||||
- if [ "$TO_TEST" = "TEST_MOCK" ] ||
|
|
||||||
[ "$TO_TEST" = "TEST_FULL" ]; then PUBS_TESTS_MODE=MOCK python setup.py test; fi
|
|
||||||
- if [ "$TO_TEST" = "TEST_FULL" ]; then PUBS_TESTS_MODE=COLLECT python setup.py test; fi
|
|
||||||
- if [ "$TO_TEST" = "INSTALL" ]; then pip install -U pip && pip install pubs && pubs --help && pip uninstall -y pubs; fi
|
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
### Implemented enhancements
|
### Implemented enhancements
|
||||||
|
|
||||||
|
- Migration from Travis CI to Github actions ([#260](https://github.com/pubs/pubs/pull/260))
|
||||||
- Allow passing named arguments to custom commands ([#241](https://github.com/pubs/pubs/pull/241) by [jkulhanek](https://github.com/jkulhanek))
|
- Allow passing named arguments to custom commands ([#241](https://github.com/pubs/pubs/pull/241) by [jkulhanek](https://github.com/jkulhanek))
|
||||||
- Added support for non-standard bibtex types, e.g. @collection, @software, etc. ([#226](https://github.com/pubs/pubs/pull/226))
|
- Added support for non-standard bibtex types, e.g. @collection, @software, etc. ([#226](https://github.com/pubs/pubs/pull/226))
|
||||||
- The number of displayed authors in listings is now configurable, as the `max_authors` value in the `main` section of the configuration. ([#225](https://github.com/pubs/pubs/pull/225))
|
- The number of displayed authors in listings is now configurable, as the `max_authors` value in the `main` section of the configuration. ([#225](https://github.com/pubs/pubs/pull/225))
|
||||||
@ -15,6 +16,7 @@
|
|||||||
|
|
||||||
### Fixed bugs
|
### Fixed bugs
|
||||||
|
|
||||||
|
- Fixed collision when entry uses `type` field ([#252](https://github.com/pubs/pubs/pull/252))
|
||||||
- Note on comma in alias descriptions ([#240](https://github.com/pubs/pubs/pull/240) [StanczakDominik](https://github.com/StanczakDominik))
|
- Note on comma in alias descriptions ([#240](https://github.com/pubs/pubs/pull/240) [StanczakDominik](https://github.com/StanczakDominik))
|
||||||
- Note path correctly expand user '~' ([#250](https://github.com/pubs/pubs/pull/250))
|
- Note path correctly expand user '~' ([#250](https://github.com/pubs/pubs/pull/250))
|
||||||
- Tests don't run on python 2.7 or <=3.4. They may still work, but support will not be tested and will eventually be dropped. ([#223](https://github.com/pubs/pubs/pull/223))
|
- Tests don't run on python 2.7 or <=3.4. They may still work, but support will not be tested and will eventually be dropped. ([#223](https://github.com/pubs/pubs/pull/223))
|
||||||
|
@ -20,8 +20,6 @@ six
|
|||||||
# those are the additional packages required to run the tests
|
# those are the additional packages required to run the tests
|
||||||
pyfakefs
|
pyfakefs
|
||||||
certifi
|
certifi
|
||||||
# FIXME: remove strict version when https://github.com/datadriventests/ddt/issues/83 is fixed.
|
ddt>=1.4.1
|
||||||
# (also remove in setup.py)
|
|
||||||
ddt==1.3.1
|
|
||||||
mock
|
mock
|
||||||
pytest
|
pytest
|
||||||
|
@ -16,11 +16,13 @@ GITIGNORE = """# files or directories for the git plugin to ignore
|
|||||||
|
|
||||||
|
|
||||||
class GitPlugin(PapersPlugin):
|
class GitPlugin(PapersPlugin):
|
||||||
"""The git plugin creates a git repository in the pubs directory and commit the changes
|
"""Make the pubs repository also a git repository.
|
||||||
to the pubs repository everytime a paper is modified.
|
|
||||||
|
|
||||||
It also add the `pubs git` subcommand, so git commands can be executed in the git repository
|
The git plugin creates a git repository in the pubs directory
|
||||||
from the command line.
|
and commit the changes to the pubs repository.
|
||||||
|
|
||||||
|
It also add the `pubs git` subcommand, so git commands can be executed
|
||||||
|
in the git repository from the command line.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = 'git'
|
name = 'git'
|
||||||
@ -28,10 +30,10 @@ class GitPlugin(PapersPlugin):
|
|||||||
|
|
||||||
def __init__(self, conf, ui):
|
def __init__(self, conf, ui):
|
||||||
self.ui = ui
|
self.ui = ui
|
||||||
self.pubsdir = os.path.expanduser(conf['main']['pubsdir'])
|
self.pubsdir = os.path.expanduser(conf['main']['pubsdir'])
|
||||||
self.manual = conf['plugins'].get('git', {}).get('manual', False)
|
self.manual = conf['plugins'].get('git', {}).get('manual', False)
|
||||||
self.force_color = conf['plugins'].get('git', {}).get('force_color', True)
|
self.force_color = conf['plugins'].get('git', {}).get('force_color', True)
|
||||||
self.quiet = conf['plugins'].get('git', {}).get('quiet', True)
|
self.quiet = conf['plugins'].get('git', {}).get('quiet', True)
|
||||||
self.list_of_changes = []
|
self.list_of_changes = []
|
||||||
self._gitinit()
|
self._gitinit()
|
||||||
|
|
||||||
@ -72,17 +74,18 @@ class GitPlugin(PapersPlugin):
|
|||||||
"""
|
"""
|
||||||
colorize = ' -c color.ui=always' if self.force_color else ''
|
colorize = ' -c color.ui=always' if self.force_color else ''
|
||||||
git_cmd = 'git -C {}{} {}'.format(self.pubsdir, colorize, cmd)
|
git_cmd = 'git -C {}{} {}'.format(self.pubsdir, colorize, cmd)
|
||||||
#print(git_cmd)
|
|
||||||
p = Popen(git_cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, shell=True)
|
p = Popen(git_cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, shell=True)
|
||||||
output, err = p.communicate(input_stdin)
|
output, err = p.communicate(input_stdin)
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise RuntimeError('The git plugin encountered an error when running the git command:\n' +
|
raise RuntimeError((
|
||||||
'{}\n\nReturned output:\n{}\n'.format(git_cmd, output.decode('utf-8')) +
|
'The git plugin encountered an error when running the git command:\n'
|
||||||
'If needed, you may fix the state of the {} git repository '.format(self.pubsdir) +
|
'{}\n\n'
|
||||||
'manually.\nIf relevant, you may submit a bug report at ' +
|
'Returned output:\n{}\n'
|
||||||
'https://github.com/pubs/pubs/issues')
|
'If needed, you may fix the state of the {} git repository manually.\n'
|
||||||
|
'If relevant, you may submit a bug report at https://github.com/pubs/pubs/issues'
|
||||||
|
).format(git_cmd, output.decode('utf-8'), self.pubsdir))
|
||||||
elif command:
|
elif command:
|
||||||
self.ui.message(output.decode('utf-8'), end='')
|
self.ui.message(output.decode('utf-8'), end='')
|
||||||
elif not self.quiet:
|
elif not self.quiet:
|
||||||
@ -97,10 +100,11 @@ def paper_change_event(event):
|
|||||||
git = GitPlugin.get_instance()
|
git = GitPlugin.get_instance()
|
||||||
if not git.manual:
|
if not git.manual:
|
||||||
event_desc = event.description
|
event_desc = event.description
|
||||||
for a, b in [('\\','\\\\'), ('"','\\"'), ('$','\\$'), ('`','\\`')]:
|
for a, b in [('\\', '\\\\'), ('"', '\\"'), ('$', '\\$'), ('`', '\\`')]:
|
||||||
event_desc = event_desc.replace(a, b)
|
event_desc = event_desc.replace(a, b)
|
||||||
git.list_of_changes.append(event_desc)
|
git.list_of_changes.append(event_desc)
|
||||||
|
|
||||||
|
|
||||||
@PostCommandEvent.listen()
|
@PostCommandEvent.listen()
|
||||||
def git_commit(event):
|
def git_commit(event):
|
||||||
if GitPlugin.is_loaded():
|
if GitPlugin.is_loaded():
|
||||||
|
2
setup.py
2
setup.py
@ -60,7 +60,7 @@ setup(
|
|||||||
],
|
],
|
||||||
|
|
||||||
test_suite='tests',
|
test_suite='tests',
|
||||||
tests_require=['pyfakefs>=3.4', 'mock', 'ddt==1.3.1', 'certifi', 'pytest'],
|
tests_require=['pyfakefs>=3.4', 'mock', 'ddt>=1.4.1', 'certifi', 'pytest'],
|
||||||
|
|
||||||
# in order to avoid 'zipimport.ZipImportError: bad local file header'
|
# in order to avoid 'zipimport.ZipImportError: bad local file header'
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import unittest
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import unittest
|
||||||
|
|
||||||
import sand_env
|
import sand_env
|
||||||
|
|
||||||
@ -16,11 +17,20 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase):
|
|||||||
|
|
||||||
def setUp(self, nsec_stat=True):
|
def setUp(self, nsec_stat=True):
|
||||||
super(TestGitPlugin, self).setUp()
|
super(TestGitPlugin, self).setUp()
|
||||||
|
# Backup environment variables and set git author
|
||||||
|
self.env_backup = os.environ.copy()
|
||||||
|
os.environ['GIT_AUTHOR_NAME'] = "Pubs test"
|
||||||
|
os.environ['GIT_AUTHOR_EMAIL'] = "unittest@pubs.org"
|
||||||
|
# Setup pubs repository
|
||||||
self.execute_cmds([('pubs init',)])
|
self.execute_cmds([('pubs init',)])
|
||||||
conf = config.load_conf(path=self.default_conf_path)
|
conf = config.load_conf(path=self.default_conf_path)
|
||||||
conf['plugins']['active'] = ['git']
|
conf['plugins']['active'] = ['git']
|
||||||
config.save_conf(conf, path=self.default_conf_path)
|
config.save_conf(conf, path=self.default_conf_path)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
|
os.environ = self.env_backup
|
||||||
|
|
||||||
def test_git(self):
|
def test_git(self):
|
||||||
self.execute_cmds([('pubs add data/pagerank.bib',)])
|
self.execute_cmds([('pubs add data/pagerank.bib',)])
|
||||||
hash_a = git_hash(self.default_pubs_dir)
|
hash_a = git_hash(self.default_pubs_dir)
|
||||||
@ -31,7 +41,7 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase):
|
|||||||
self.execute_cmds([('pubs rename Page99a ABC',)])
|
self.execute_cmds([('pubs rename Page99a ABC',)])
|
||||||
hash_c = git_hash(self.default_pubs_dir)
|
hash_c = git_hash(self.default_pubs_dir)
|
||||||
|
|
||||||
self.execute_cmds([('pubs remove ABC', ['y']),])
|
self.execute_cmds([('pubs remove ABC', ['y'])])
|
||||||
hash_d = git_hash(self.default_pubs_dir)
|
hash_d = git_hash(self.default_pubs_dir)
|
||||||
|
|
||||||
self.execute_cmds([('pubs doc add testrepo/doc/Page99.pdf Page99',)])
|
self.execute_cmds([('pubs doc add testrepo/doc/Page99.pdf Page99',)])
|
||||||
@ -72,6 +82,7 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase):
|
|||||||
# self.assertEqual(hash_i, hash_j)
|
# self.assertEqual(hash_i, hash_j)
|
||||||
|
|
||||||
def test_manual(self):
|
def test_manual(self):
|
||||||
|
print(self.default_pubs_dir)
|
||||||
conf = config.load_conf(path=self.default_conf_path)
|
conf = config.load_conf(path=self.default_conf_path)
|
||||||
conf['plugins']['active'] = ['git']
|
conf['plugins']['active'] = ['git']
|
||||||
conf['plugins']['git']['manual'] = True
|
conf['plugins']['git']['manual'] = True
|
||||||
@ -101,6 +112,5 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase):
|
|||||||
self.assertNotEqual(hash_l, hash_m)
|
self.assertNotEqual(hash_l, hash_m)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user