From 1865e64ce37e1d1178cfd64a0a0705b4d7946124 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Sun, 24 Jan 2021 17:54:33 -0800 Subject: [PATCH 1/9] Update ddt dependency after upstream bug fix. --- dev_requirements.txt | 4 +--- setup.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index b9879c5..0b107fb 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -20,8 +20,6 @@ six # those are the additional packages required to run the tests pyfakefs certifi -# FIXME: remove strict version when https://github.com/datadriventests/ddt/issues/83 is fixed. -# (also remove in setup.py) -ddt==1.3.1 +ddt>=1.4.1 mock pytest diff --git a/setup.py b/setup.py index f5e45d2..011ad68 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( ], 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' zip_safe=False, From 741392658984deabddf0a6612e3cdd6bbee449ab Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 25 Jan 2021 21:37:45 -0800 Subject: [PATCH 2/9] Add github test workflow. --- .github/workflows/tests.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..fbad0e9 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,30 @@ +name: Pubs tests + +on: [push, pull_request] + +jobs: + unit-test: + 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: 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 From 526ed05c4133c2cd383ffd6ed9cddc02eb32fe51 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 25 Jan 2021 22:05:34 -0800 Subject: [PATCH 3/9] PEP8 and cosmetic changes. --- pubs/plugs/git/git.py | 32 ++++++++++++++++++-------------- tests/test_git.py | 3 +-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pubs/plugs/git/git.py b/pubs/plugs/git/git.py index 5be9221..3bff3d6 100644 --- a/pubs/plugs/git/git.py +++ b/pubs/plugs/git/git.py @@ -16,11 +16,13 @@ GITIGNORE = """# files or directories for the git plugin to ignore class GitPlugin(PapersPlugin): - """The git plugin creates a git repository in the pubs directory and commit the changes - to the pubs repository everytime a paper is modified. + """Make the pubs repository also a git repository. - It also add the `pubs git` subcommand, so git commands can be executed in the git repository - from the command line. + The git plugin creates a git repository in the pubs directory + 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' @@ -28,10 +30,10 @@ class GitPlugin(PapersPlugin): def __init__(self, conf, ui): self.ui = ui - self.pubsdir = os.path.expanduser(conf['main']['pubsdir']) - self.manual = conf['plugins'].get('git', {}).get('manual', False) + self.pubsdir = os.path.expanduser(conf['main']['pubsdir']) + self.manual = conf['plugins'].get('git', {}).get('manual', False) 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._gitinit() @@ -72,17 +74,18 @@ class GitPlugin(PapersPlugin): """ colorize = ' -c color.ui=always' if self.force_color else '' git_cmd = 'git -C {}{} {}'.format(self.pubsdir, colorize, cmd) - #print(git_cmd) p = Popen(git_cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, shell=True) output, err = p.communicate(input_stdin) p.wait() if p.returncode != 0: - raise RuntimeError('The git plugin encountered an error when running the git command:\n' + - '{}\n\nReturned output:\n{}\n'.format(git_cmd, output.decode('utf-8')) + - 'If needed, you may fix the state of the {} git repository '.format(self.pubsdir) + - 'manually.\nIf relevant, you may submit a bug report at ' + - 'https://github.com/pubs/pubs/issues') + raise RuntimeError(( + 'The git plugin encountered an error when running the git command:\n' + '{}\n\n' + 'Returned output:\n{}\n' + '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: self.ui.message(output.decode('utf-8'), end='') elif not self.quiet: @@ -97,10 +100,11 @@ def paper_change_event(event): git = GitPlugin.get_instance() if not git.manual: event_desc = event.description - for a, b in [('\\','\\\\'), ('"','\\"'), ('$','\\$'), ('`','\\`')]: + for a, b in [('\\', '\\\\'), ('"', '\\"'), ('$', '\\$'), ('`', '\\`')]: event_desc = event_desc.replace(a, b) git.list_of_changes.append(event_desc) + @PostCommandEvent.listen() def git_commit(event): if GitPlugin.is_loaded(): diff --git a/tests/test_git.py b/tests/test_git.py index 9eb60f8..192c042 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -31,7 +31,7 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): self.execute_cmds([('pubs rename Page99a ABC',)]) 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) self.execute_cmds([('pubs doc add testrepo/doc/Page99.pdf Page99',)]) @@ -101,6 +101,5 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): self.assertNotEqual(hash_l, hash_m) - if __name__ == '__main__': unittest.main() From fd2227b5482a080a0c74c1b4cb4e7aaec7914dbb Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 25 Jan 2021 22:18:47 -0800 Subject: [PATCH 4/9] Fix git plugin tests. Add fake author info to environment while running the tests to avoid failure of the git commit commands. --- .github/workflows/tests.yaml | 7 +++++++ tests/test_git.py | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fbad0e9..fb2b8e0 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -20,6 +20,13 @@ jobs: 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 diff --git a/tests/test_git.py b/tests/test_git.py index 192c042..d9926ba 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -1,5 +1,6 @@ -import unittest +import os import subprocess +import unittest import sand_env @@ -16,12 +17,22 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): def setUp(self, nsec_stat=True): 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',)]) conf = config.load_conf(path=self.default_conf_path) conf['plugins']['active'] = ['git'] config.save_conf(conf, path=self.default_conf_path) + def tearDown(self): + super().tearDown() + os.environ = self.env_backup + def test_git(self): + print(self.default_pubs_dir) self.execute_cmds([('pubs add data/pagerank.bib',)]) hash_a = git_hash(self.default_pubs_dir) @@ -72,6 +83,7 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): # self.assertEqual(hash_i, hash_j) def test_manual(self): + print(self.default_pubs_dir) conf = config.load_conf(path=self.default_conf_path) conf['plugins']['active'] = ['git'] conf['plugins']['git']['manual'] = True From 745db24eaf76762a3c500fe3a88919c1baf1dec7 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 25 Jan 2021 23:05:19 -0800 Subject: [PATCH 5/9] Add install test to github action with cron trigger. The install test is only run when the cron event is the trigger. --- .github/workflows/tests.yaml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fb2b8e0..28dbaeb 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,9 +1,15 @@ name: Pubs tests -on: [push, pull_request] +on: + push: + pull_request: + schedule: + - cron: '0 8 * * *' + jobs: unit-test: + name: Run unit tests strategy: matrix: os: [macos-latest, ubuntu-latest] @@ -35,3 +41,20 @@ jobs: 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 == 'cron' + + steps: + - uses: actions/setup-python@v2 + - name: install test + run: | + pip install -U pip + pip install pubs + pubs --help + pip uninstall -y pubs From d89cc30862872a373492d855e4a0be6f47a989d5 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Mon, 25 Jan 2021 23:14:53 -0800 Subject: [PATCH 6/9] Remove travis configuration. --- .travis.yml | 89 ----------------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a03b5d2..0000000 --- a/.travis.yml +++ /dev/null @@ -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 From 427af1b4b3379e505d065e18a559798f92f337cb Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Wed, 27 Jan 2021 23:13:40 -0800 Subject: [PATCH 7/9] Use correct event name in workflow. --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 28dbaeb..af0312e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -48,7 +48,7 @@ jobs: matrix: os: [macos-latest, ubuntu-latest] runs-on: ${{ matrix.os }} - if: github.event_name == 'cron' + if: github.event_name == 'schedule' steps: - uses: actions/setup-python@v2 From 6e31a98c1898dee6837c44249cb10f9f5c210f10 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Fri, 29 Jan 2021 21:08:35 -0800 Subject: [PATCH 8/9] Minor: forgotten print. --- tests/test_git.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_git.py b/tests/test_git.py index d9926ba..d25e6e7 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -32,7 +32,6 @@ class TestGitPlugin(sand_env.SandboxedCommandTestCase): os.environ = self.env_backup def test_git(self): - print(self.default_pubs_dir) self.execute_cmds([('pubs add data/pagerank.bib',)]) hash_a = git_hash(self.default_pubs_dir) From a6b63ccafad160051c5f273072b135582fd10c69 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Fri, 29 Jan 2021 21:12:25 -0800 Subject: [PATCH 9/9] Changelog update. --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index 0a25116..ca05610 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ ### 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)) - 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)) @@ -15,6 +16,7 @@ ### 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 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))