perrette / papers

Command-line tool to manage bibliography (pdfs + bibtex)
MIT License
142 stars 22 forks source link

Tests fail when ``.papers`` does not exist. #45

Closed boyanpenkov closed 1 year ago

boyanpenkov commented 1 year ago

This is kinda nit-picky and it's not even clear if it's worth a "fix", but when the .papers dir does not exist, a test fails:

__________________________________________ TestAdd2.test_add ___________________________________________
[gw2] linux -- Python 3.11.3 /home/boyan/boyanshouse/miniconda3/envs/python311/bin/python

self = <test_papers.TestAdd2 testMethod=test_add>

    def test_add(self):
        self.assertTrue(os.path.exists(self.mybib))
        print("bibtex", self.mybib, 'exists?', os.path.exists(self.mybib))
>       sp.check_call('papers add --bibtex {} {}'.format(
            self.mybib, self.pdf), shell=True)

tests/test_papers.py:177: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

popenargs = ('papers add --bibtex /tmp/papers.biba8iolx_d /home/boyan/boyanshouse/Vazhno/Work/papers/tests/downloadedpapers/esd-4-11-2013.pdf',)
kwargs = {'shell': True}, retcode = 1
cmd = 'papers add --bibtex /tmp/papers.biba8iolx_d /home/boyan/boyanshouse/Vazhno/Work/papers/tests/downloadedpapers/esd-4-11-2013.pdf'

    def check_call(*popenargs, **kwargs):
        """Run command with arguments.  Wait for command to complete.  If
        the exit code was zero then return, otherwise raise
        CalledProcessError.  The CalledProcessError object will have the
        return code in the returncode attribute.

        The arguments are the same as for the call function.  Example:

        check_call(["ls", "-l"])
        """
        retcode = call(*popenargs, **kwargs)
        if retcode:
            cmd = kwargs.get("args")
            if cmd is None:
                cmd = popenargs[0]
>           raise CalledProcessError(retcode, cmd)
E           subprocess.CalledProcessError: Command 'papers add --bibtex /tmp/papers.biba8iolx_d /home/boyan/boyanshouse/Vazhno/Work/papers/tests/downloadedpapers/esd-4-11-2013.pdf' returned non-zero exit status 1.

../../../miniconda3/envs/python311/lib/python3.11/subprocess.py:413: CalledProcessError
----------------------------------------- Captured stdout call ------------------------------------------
bibtex /tmp/papers.biba8iolx_d exists? True
----------------------------------------- Captured stderr call ------------------------------------------
Traceback (most recent call last):
  File "/home/boyan/boyanshouse/miniconda3/envs/python311/bin/papers", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/boyan/boyanshouse/Vazhno/Work/papers/papers/bib.py", line 1577, in main
    check_install() and addcmd(o)
    ^^^^^^^^^^^^^^^
  File "/home/boyan/boyanshouse/Vazhno/Work/papers/papers/bib.py", line 1568, in check_install
    logger.info('filesdir: '+config.filesdir)
                ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str
perrette commented 1 year ago

No no that must be fixed. That's related to recent changes that do not impose a choice for filesdir. So that the user has to explicitly agree where the files are stored (#32 and related subsequent commits).

The whole issue deserves a discussion in itself. It's related to papers moving from a black-box install with opinionated global defaults towards a more explicit tool to fulfill more specifically defined tasks.

The default is None instead of previously "~/.config/papers/files" A repr(config.filesdir), or using f-string instead of + string concatenation will fix that one. It's strange the CI tests didn't pick that one up earlier.

perrette commented 1 year ago

Should be solved now.