Skip to content

Commit

Permalink
Test GRABSEEDS (#663)
Browse files Browse the repository at this point in the history
* Add test_grabseeds.py

* no freetype on ubuntu

* Add pytesseract

* use libmagickwand-dev on ubuntu

* Add PAGE_RANGE_HELP

* PdfFileMerger => PdfMerger
  • Loading branch information
tanghaibao authored May 10, 2024
1 parent 0c55cf6 commit 00c1dc7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
cache: 'pip'

- name: Install BEDTools (Linux)
run: sudo apt-get install bedtools
run: sudo apt-get install bedtools libmagickwand-dev
if: matrix.os == 'ubuntu-latest'

- name: Install BEDTools (macOS)
run: brew install bedtools
run: brew install bedtools freetype imagemagick
if: matrix.os == 'macos-13'

- name: Install dependencies
Expand Down
8 changes: 5 additions & 3 deletions jcvi/formats/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

from natsort import natsorted

from PyPDF2 import PdfFileMerger, parse_filename_page_ranges
from PyPDF2.pagerange import PAGE_RANGE_HELP
from pypdf import PdfMerger, parse_filename_page_ranges
from pypdf.pagerange import PageRange

from ..apps.base import ActionDispatcher, OptionParser, cleanup, logger

from .base import must_open

PAGE_RANGE_HELP = PageRange.__init__.__doc__


def main():

Expand Down Expand Up @@ -75,7 +77,7 @@ def cat(args):

filename_page_ranges = parse_filename_page_ranges(args)
nfiles = len(filename_page_ranges)
merger = PdfFileMerger()
merger = PdfMerger()
with must_open(outfile, "wb") as fw:
in_fs = {}
try:
Expand Down
2 changes: 1 addition & 1 deletion jcvi/graphics/grabseeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def seeds(args):
ff = opts.filter
calib = opts.calibrate
outdir = opts.outdir
if outdir != ".":
if outdir and outdir != ".":
mkdir(outdir)
if calib:
calib = json.load(must_open(calib))
Expand Down
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ zip_safe = False
setup_requires = setuptools>=18.0; cython
install_requires =
CrossMap
PyPDF2
Wand
biopython
boto3
brewer2mpl
Expand All @@ -53,6 +53,8 @@ install_requires =
ortools
pybedtools
pyefd
pypdf
pytesseract
rich
scikit-image
scipy
Expand Down
Binary file added tests/graphics/data/calibrate.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/graphics/data/test.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions tests/graphics/test_grabseeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import os.path as op

from jcvi.apps.base import cleanup
from jcvi.graphics.grabseeds import calibrate, seeds


def test_main():
cwd = os.getcwd()
os.chdir(op.join(op.dirname(__file__), "data"))
output_image = "test.pdf"
json_file = "calibrate.json"
cleanup(output_image)
seeds(["test.JPG"])
assert op.exists(output_image)

# Test calibrate
json_file = "calibrate.json"
cleanup(json_file, output_image)
json_file = calibrate(["calibrate.JPG", "1"]) # `1` for the boxsize arg
assert op.exists(json_file)
seeds(["test.JPG", "--calibrate", json_file])

os.chdir(cwd)

0 comments on commit 00c1dc7

Please sign in to comment.