Permalink
Browse files

More tests; cope with UnknownPosition in no-fuzzy start/end

  • Loading branch information...
peterjc committed Aug 30, 2012
1 parent 7af641f commit f8c66465647351fec4c3f9b505ac05fc2c361550
Showing with 46 additions and 8 deletions.
  1. +38 −8 Bio/SeqFeature.py
  2. +8 −0 Tests/seq_tests_common.py
View
@@ -846,21 +846,31 @@ def end(self):
def nofuzzy_start(self):
"""Start position (integer, approximated if fuzzy, read only) (OBSOLETE).
- This is now a alias for int(feature.start), which should be
+ This is now an alias for int(feature.start), which should be
used in preference -- unless you are trying to support old
versions of Biopython.
"""
- return int(self._start)
+ try:
+ return int(self._start)
+ except TypeError:
+ if isinstance(self._start, UnknownPosition):
+ return None
+ raise
@property
def nofuzzy_end(self):
"""End position (integer, approximated if fuzzy, read only) (OBSOLETE).
- This is now a alias for int(feature.end), which should be
+ This is now an alias for int(feature.end), which should be
used in preference -- unless you are trying to support old
versions of Biopython.
"""
- return int(self._end)
+ try:
+ return int(self._end)
+ except TypeError:
+ if isinstance(self._end, UnknownPosition):
+ return None
+ raise
def extract(self, parent_sequence):
"""Extract feature sequence from the supplied parent sequence."""
@@ -1085,13 +1095,33 @@ def end(self):
@property
def nofuzzy_start(self):
- """Start position (integer, approximated if fuzzy, read only) (OBSOLETE)."""
- return int(self.start)
+ """Start position (integer, approximated if fuzzy, read only) (OBSOLETE).
+
+ This is an alias for int(feature.start), which should be used in
+ preference -- unless you are trying to support old versions of
+ Biopython.
+ """
+ try:
+ return int(self.start)
+ except TypeError:
+ if isinstance(self.start, UnknownPosition):
+ return None
+ raise
@property
def nofuzzy_end(self):
- """End position (integer, approximated if fuzzy, read only) (OBSOLETE)."""
- return int(self.end)
+ """End position (integer, approximated if fuzzy, read only) (OBSOLETE).
+
+ This is an alias for int(feature.end), which should be used in
+ preference -- unless you are trying to support old versions of
+ Biopython.
+ """
+ try:
+ return int(self.end)
+ except TypeError:
+ if isinstance(self.end, UnknownPosition):
+ return None
+ raise
@property
def ref(self):
@@ -114,12 +114,20 @@ def compare_feature(old_f, new_f):
assert old_l.ref == new_l.ref
assert old_l.ref_db == new_l.ref_db
+ assert len(old_f.location.parts) == len(new_f.location.parts)
+ for old_sub, new_sub in zip(old_f.location.parts, new_f.location.parts):
+ #These are FeatureLocation objects
+ assert old_sub.nofuzzy_start == new_sub.nofuzzy_start
+ assert old_sub.nofuzzy_end == new_sub.nofuzzy_end
+ assert old_sub.strand == new_sub.strand
+
#Using private variable to avoid deprecation warnings
assert len(old_f._sub_features) == len(new_f._sub_features), \
"number of sub_features: %s -> %s" % \
(len(old_f._sub_features), len(new_f._sub_features))
for old_sub, new_sub in zip(old_f._sub_features, new_f._sub_features):
+ #These are SeqFeature objects
assert old_sub.type == new_sub.type, \
"%s -> %s" % (old_sub.type, new_sub.type)

0 comments on commit f8c6646

Please sign in to comment.