|
| 1 | +#from pypdfocr import PyPDFOCR as P |
| 2 | +import pypdfocr.pypdfocr as P |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +class TestOptions: |
| 7 | + |
| 8 | + def setup(self): |
| 9 | + self.p = P.PyPDFOCR() |
| 10 | + |
| 11 | + |
| 12 | + def test_standalone(self): |
| 13 | + opts = ["blah.pdf"] |
| 14 | + self.p.get_options(opts) |
| 15 | + |
| 16 | + opts.append('-d') |
| 17 | + self.p.get_options(opts) |
| 18 | + assert(self.p.debug) |
| 19 | + |
| 20 | + opts.append('-v') |
| 21 | + self.p.get_options(opts) |
| 22 | + assert(self.p.verbose) |
| 23 | + |
| 24 | + assert(not self.p.enable_filing) |
| 25 | + with pytest.raises(AttributeError): |
| 26 | + self.p.config |
| 27 | + |
| 28 | + def test_standalone_filing(self): |
| 29 | + opts = ["blah.pdf"] |
| 30 | + opts.append('-f') |
| 31 | + |
| 32 | + # Assert that filing option requires a config file |
| 33 | + with pytest.raises(SystemExit): |
| 34 | + self.p.get_options(opts) |
| 35 | + |
| 36 | + # Assert that it checks that the config file is present |
| 37 | + opts.append('--config=test_option_config.yaml') |
| 38 | + self.p.get_options(opts) |
| 39 | + assert(self.p.enable_filing) |
| 40 | + assert(self.p.config) |
| 41 | + |
| 42 | + def test_standalone_filing_evernote(self): |
| 43 | + # Check when evernote is enabled |
| 44 | + opts = ["blah.pdf"] |
| 45 | + opts.append('-e') |
| 46 | + # Assert that it checks that the config file is present |
| 47 | + with pytest.raises(SystemExit): |
| 48 | + self.p.get_options(opts) |
| 49 | + |
| 50 | + opts.append('--config=test_option_config.yaml') |
| 51 | + self.p.get_options(opts) |
| 52 | + # Enabling -e should turn on filing too |
| 53 | + assert(self.p.enable_filing) |
| 54 | + assert(self.p.enable_evernote) |
| 55 | + assert(self.p.config) |
| 56 | + assert(not self.p.watch) |
| 57 | + |
| 58 | + opts.append('-f') |
| 59 | + self.p.get_options(opts) |
| 60 | + assert(self.p.enable_filing) |
| 61 | + assert(self.p.enable_evernote) |
| 62 | + assert(self.p.config) |
| 63 | + assert(not self.p.watch) |
| 64 | + |
| 65 | + def test_standalone_watch_conflict(self): |
| 66 | + # When pdf file is specified, we don't want to allow watch option |
| 67 | + opts = ["blah.pdf", '-w'] |
| 68 | + with pytest.raises(SystemExit): |
| 69 | + self.p.get_options(opts) |
| 70 | + |
| 71 | + def test_watch_filing(self): |
| 72 | + opts = ['-w'] |
| 73 | + # Catch watch without a dir |
| 74 | + with pytest.raises(SystemExit): |
| 75 | + self.p.get_options(opts) |
| 76 | + |
| 77 | + opts = ['-w temp'] |
| 78 | + self.p.get_options(opts) |
| 79 | + assert(self.p.watch_dir) |
| 80 | + |
| 81 | + opts.append('--config=test_option_config.yaml') |
| 82 | + self.p.get_options(opts) |
| 83 | + assert(self.p.watch) |
| 84 | + assert(self.p.config) |
| 85 | + assert(not self.p.enable_filing) |
| 86 | + assert(not self.p.enable_evernote) |
| 87 | + |
| 88 | + def test_watch_filing_evernote(self): |
| 89 | + opts = ['-w temp', '-e', '--config=test_option_config.yaml'] |
| 90 | + self.p.get_options(opts) |
| 91 | + assert(self.p.watch) |
| 92 | + assert(self.p.config) |
| 93 | + assert(self.p.enable_filing) |
| 94 | + assert(self.p.enable_evernote) |
| 95 | + |
| 96 | + opts = ['-w temp', '-f', '-e', '--config=test_option_config.yaml'] |
| 97 | + self.p.get_options(opts) |
| 98 | + assert(self.p.watch) |
| 99 | + assert(self.p.config) |
| 100 | + assert(self.p.enable_filing) |
| 101 | + assert(self.p.enable_evernote) |
| 102 | + |
0 commit comments