Skip to content

Commit

Permalink
pdb_validate outputs to sys.stdout (haddocking#44)
Browse files Browse the repository at this point in the history
* changed stderr to stdout in validation function

* changed tests
  • Loading branch information
joaomcteixeira committed Mar 18, 2020
1 parent b39fb96 commit 82dc983
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions pdbtools/pdb_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,23 @@ def _make_pointer(column):
linelen = len(line)
if linelen < 80:
emsg = '[!] Line {0} is short: {1} < 80\n'
sys.stderr.write(emsg.format(iline, linelen))
sys.stdout.write(emsg.format(iline, linelen))
has_error = True

elif linelen > 80:
emsg = '[!] Line {0} is long: {1} > 80\n'
sys.stderr.write(emsg.format(iline, linelen))
sys.stdout.write(emsg.format(iline, linelen))
has_error = True

for fname, (fcol, fcheck) in _fmt_check:
field = line[fcol]
if not fcheck.match(field):
pointer = _make_pointer(fcol)
emsg = '[!] Offending field ({0}) at line {1}\n'
sys.stderr.write(emsg.format(fname, iline))
sys.stdout.write(emsg.format(fname, iline))

sys.stderr.write(repr(line) + '\n')
sys.stderr.write(pointer + '\n')
sys.stdout.write(repr(line) + '\n')
sys.stdout.write(pointer + '\n')

has_error = True
break
Expand All @@ -142,17 +142,17 @@ def _make_pointer(column):
linelen = len(line)
if linelen < 80:
emsg = '[!] Line {0} is short: {1} < 80\n'
sys.stderr.write(emsg.format(iline, linelen))
sys.stdout.write(emsg.format(iline, linelen))
has_error = True
elif linelen > 80:
emsg = '[!] Line {0} is long: {1} > 80\n'
sys.stderr.write(emsg.format(iline, linelen))
sys.stdout.write(emsg.format(iline, linelen))
has_error = True

if has_error:
msg = '\nTo understand your errors, read the format specification:\n'
msg += ' http://www.wwpdb.org/documentation/file-format-content/format33/sect9.html#ATOM\n'
sys.stderr.write(msg)
sys.stdout.write(msg)
return 1
else:
msg = 'It *seems* everything is OK.'
Expand Down
12 changes: 6 additions & 6 deletions tests/test_pdb_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def test_warnings(self):

# Validate results
self.assertEqual(self.retcode, 1)
self.assertEqual(len(self.stdout), 0)
self.assertEqual(len(self.stderr), 253)
self.assertEqual(len(self.stdout), 253)
self.assertEqual(len(self.stderr), 0)

# Count no. of line length warnings
n_warn = len([l for l in self.stderr if 'is short' in l])
n_warn = len([l for l in self.stdout if 'is short' in l])
self.assertEqual(n_warn, 70)

self.assertEqual(self.stderr[-4],
self.assertEqual(self.stdout[-4],
"[!] Line 203 is short: 26 < 80")

def test_valid(self):
Expand All @@ -85,8 +85,8 @@ def test_valid(self):

# Validate results
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
self.assertEqual(len(self.stdout), 1)
self.assertEqual(len(self.stderr), 0) # no errors
self.assertEqual(len(self.stderr), 0)
self.assertEqual(len(self.stdout), 1) # no errors

self.assertEqual(self.stdout,
["It *seems* everything is OK."])
Expand Down

0 comments on commit 82dc983

Please sign in to comment.