Commit Graph

31 Commits

Author SHA1 Message Date
57056bbfc4 ruff format v0.3.1, black v24.2.0
Reverted unwanted changes (mostly arrays in tests, but also
some whitespace in doctests).

Remaining changes are standardising spacing between module
docstring and imports, and lower-case \x<hex> in strings.
2024-03-14 11:05:43 +00:00
74a43437e9 Abstract Base Class for Bio/File.py (#2731)
Recommended to raise still: https://docs.python.org/3/library/exceptions.html#NotImplementedError
2020-08-02 17:01:54 +01:00
106d9e9df6 Apply black styling to remaining non-formatted tests 2020-07-25 17:14:42 +01:00
98622c4944 Implements assert changes as detailed in biopython #2698 2020-02-29 15:12:10 +00:00
6a425121a8 moving UndoHandle, second attempt (#2514)
* moving UndoHandle, second attempt

* travis
2020-01-16 13:02:14 +09:00
827429d3d8 remove python2 import for StringIO 2019-12-27 16:45:02 +00:00
ede89f8e3a Assume Python 3.6+ in test_File.py 2019-12-26 11:27:12 +00:00
0c25556525 Removed print_function and division future imports 2019-12-25 14:41:32 +00:00
1b9e569a7f Using tool unify to convert Tests/ to use double quotes
Using https://github.com/myint/unify for this:

$ unify --quote \" --in-place Tests/*.py Tests/*/*.py
2019-08-02 14:10:22 +01:00
8f29a851fc Docstring fixes for flake8 - D202, D300, D401 etc
Plus a few other related fixes like adding missing docstrings.
2019-04-19 14:02:58 +01:00
c098f8d77f ValueError if _open_for_random_access given gzipped file
Still accepts BGZF, but will now error on other gzipped
files (previously would just open them in rb mode).

This is intended to close #1666
2018-09-04 10:41:31 +01:00
c25f5c2c8f Fix typo 2018-09-04 10:36:03 +01:00
7e4cdf9434 More E127 and E128 fixes, fixed removed whitespace 2018-09-04 10:36:03 +01:00
9c8b5f6c6b Also test File.as_handle with a custom path-like object 2018-03-12 14:05:40 +01:00
ef0e76c9ed Tests.test_File.AsHandleTestCase: change assertion in test_stringio
The docstring of Bio.File.as_handle (currently) contains:

    All other inputs are returned, and are *not* closed.

As such, we should really test object identity here instead of object
equality; I don't think a StringIO object will ever compare unequal to
itself, but the intention of this test is to verify that we get the same
object back from `File.as_handle` if it's not something that can be
understood by `open`.

I considered replacing this test with a `test_arbitrary_object` test
case that passed an `object()` to `File.as_handle`, but that seems like
unnecessary code churn.
2017-12-27 23:53:47 +00:00
e186e7deff Tests.test_File.AsHandleTestCase: add test_path_object test
Under Python >= 3.6, test passing a `pathlib.Path` object to
`File.as_handle`.
2017-12-27 23:53:47 +00:00
1b02496856 Docstring style in Tests
Fixed various issues including:

D403: First word of the first line should be properly capitalized
2017-08-24 13:46:07 +01:00
f8c9f59c28 Make test_File.py into pure unittest
(Think only half of it was being tested before)

Added a basic UndoHandle.read(block) test too.
2015-04-17 12:24:49 +01:00
82272b1f36 autopep8 E265 - Format block comments.
$ autopep8 --version
autopep8 1.0.4
$ autopep8 -r -i --select E265 ...
2014-10-27 14:27:12 +00:00
de12c5e08f Add: from __future__ import print_statement
This is currently redundant as we are carefully only
using this simple print style which is both a print
statement (with redundant brackets) under Python 2
and a print function under Python 3:

print(variable)

However, adding the __future__ import to any file using
a print should catch any accidental usage of the print
statement in the near future (even if not testing under
Python 3 where it would be spotted since we've turned
off the print fixer during the 2to3 conversion).

This was automated as follows:

<python>
MAGIC = "from __future__ import print_function"

import os
import sys

def should_mark(filename):
    handle = open(filename, "rU")
    lines = [line.strip() for line in handle if "print" in line]
    handle.close()
    if MAGIC in lines:
        #print("%s is marked" % filename)
        return False
    if "print" in lines:
        print("TODO - %s has a naked print" % filename)
        sys.exit(1)
    for line in lines:
        if "print" not in line:
            continue
        #print(line)
        line = line.strip(" #")
        if line.startswith(">>>") or line.startswith("..."):
            #doctest
            line = line[3:].strip()
        if line.startswith("print ") or line.startswith("print("):
            return True
    print("%s has no print statements" % filename)
    return False

def mark_file(filename, marker=MAGIC):
    with open(filename, "rU") as h:
        lines = list(h.readlines())
    with open(filename, "w") as h:
        while (lines[0].startswith("#") or not lines[0].strip()):
            h.write(lines.pop(0))
        if lines[0].startswith('"""') or lines[0].startswith('r"""'):
            # Module docstring
            if lines[0].strip() == '"""':
                print("Non-PEP8 module docstring in %s" % filename)
            if lines[0].rstrip().endswith('"""') and lines[0].strip() != '"""':
                # One liner
                print("One line module docstring in %s" % filename)
                h.write(lines.pop(0))
            else:
                h.write(lines.pop(0))
                while not lines[0].strip().endswith('"""'):
                    h.write(lines.pop(0))
                h.write(lines.pop(0))
        while (lines[0].startswith("#") or not lines[0].strip()):
            h.write(lines.pop(0))
        h.write(marker + "\n\n")
        h.write("".join(lines))

for dirpath, dirnames, filenames in os.walk("."):
    if dirpath.startswith("./build/"):
        continue
    for f in filenames:
        if not f.endswith(".py"):
            continue
        f = os.path.join(dirpath, f)
        if should_mark(f):
            print("Marking %s" % f)
            mark_file(f)
</python>
2013-09-09 21:17:13 +01:00
b09ebbf6f8 Import StringIO via _py3k module in tests 2013-09-07 11:54:14 +01:00
7378e8aa50 Partially migrated to print-function-like syntax
For now we only handle the 'print' statement with a single argument,
  i. e.:

      print ... -> print(...)

  Migration was performed using a 2to3 fixer class:

      from lib2to3 import fixer_base, patcomp
      from lib2to3.fixer_util import Name, Call

      parend_expr = patcomp.compile_pattern(
          """atom< '(' [atom|term|testlist_gexp|STRING|NAME] ')' >""")

      class FixSinglePrint(fixer_base.BaseFix):
          PATTERN = "print_stmt"
          BM_compatible = True

          def transform(self, node, results):
              assert results
              assert node.children[0] == Name(u"print")
              args = node.children[1:]
              if len(args) != 1 or parend_expr.match(args[0]):
                  # We only fix 'print' statements which have _exactly_ one
                  # non-parenthesized argument.
                  return

              l_args = [arg.clone() for arg in args]
              l_args[0].prefix = u""
              n_stmt = Call(Name(u"print"), l_args)
              n_stmt.prefix = node.prefix
              return n_stmt
2013-08-31 00:54:26 +04:00
eeab501987 Remove with_statement imports required under Python 2.5
Removed all the with statement imports
(and any comment lines associated with them);

from __future__ import with_statement
2013-08-28 23:35:05 +01:00
084c89800e Remove deprecated Bio.File.StringHandle and SGMLStripper
Also removes Bio.ParserSupport.SGMLStrippingConsumer
2013-02-04 11:43:03 +00:00
fd82a0a7a7 Add blank lines where needed (PEP8 E302). 2012-12-06 10:43:43 +08:00
9c76921b91 Remove excessive blank lines (PEP8 E303). 2012-12-05 09:22:22 +00:00
558a91d824 Add AsHandleTestCase 2011-10-05 17:56:41 +01:00
1101a8f317 new regression tests for UndoHandle.read 2001-08-28 21:14:56 +00:00
b36ee1047c made my regression testing code fit into Andrew's framework 2000-05-14 00:46:52 +00:00
4ed16fe6ad added a StringHandle to File.py
removed open and urlopen functions from File.py
scanners now take normal handles
2000-02-15 23:46:26 +00:00
857211e794 added File.py and test_File.py 2000-02-10 20:41:53 +00:00