fortpy icon indicating copy to clipboard operation
fortpy copied to clipboard

Error thrown by unit test isn't string

Open jerjorg opened this issue 7 years ago • 1 comments

When I run my unit tests, I get an error.

(BZI) src$ runtests.py .
subroutine symmetryReduceKpointList
   COPY /users/jj/codes/kgridgen/src/generatekpoints.f90
   CASES:
     Wrote Test: kpts-sc
     Wrote Test: wts-sc
Running for compilers: gfortran

Executing kpts-sc.x in /Users/jj/Codes/kgridGen/unittests/kpointgeneration.symmetryReduceKpointList.g49/tests
Running vasp8:  94%|███████████████████████████████████████████████████████████████████████████████████████████████████▍      | 15/16 [00:37<00:02,  2.49s/it]Traceback (most recent call last):
  File "/Users/jj/.virtualenvs/BZI/bin/runtests.py", line 184, in <module>
    do_testing(args)
  File "/Users/jj/.virtualenvs/BZI/bin/runtests.py", line 55, in do_testing
    result = t.runall(c)
  File "/Users/jj/.virtualenvs/BZI/lib/python3.6/site-packages/fortpy/testing/tester.py", line 638, in runall
    oneresult = self._run_single(identifier, testid, source)
  File "/Users/jj/.virtualenvs/BZI/lib/python3.6/site-packages/fortpy/testing/tester.py", line 654, in _run_single
    self._run_exec(identifier, testid, result)
  File "/Users/jj/.virtualenvs/BZI/lib/python3.6/site-packages/fortpy/testing/tester.py", line 720, in _run_exec
    self.writer(identifier))
  File "/Users/jj/.virtualenvs/BZI/lib/python3.6/site-packages/fortpy/testing/tester.py", line 796, in _run_folder
    (case, start_time, code) = _execute_testpath(casepath, exepath, self.quiet, case, self.debug)
  File "/Users/jj/.virtualenvs/BZI/lib/python3.6/site-packages/fortpy/testing/tester.py", line 892, in _execute_testpath
    msg.err('\n  '+'  '.join(error))
TypeError: sequence item 0: expected str instance, bytes found
(BZI) src$ 

This is because the error is a list of bytes

error = [b'STOP The k-grid vectors that were passed in are linearly dependent.\n']

I was able to fix it by replacing

    if len(error) > 0:
        if quiet:
            msg.info("With Executable at {}".format(exepath), 1)
        msg.err('\n  '+'  '.join(error))

with

 if len(error) > 0:
        if quiet:
            msg.info("With Executable at {}".format(exepath), 1)
        try:
            msg.err('\n  '+'  '.join(error))
        except:
            msg.err('\n  '+'  '.join(error[0].strip().decode("utf-8")))

in fortpy/testing/tester.py. I now get

runtests.py .
subroutine symmetryReduceKpointList
   COPY /users/jj/codes/kgridgen/src/generatekpoints.f90
   CASES:
     Wrote Test: kpts-sc
     Wrote Test: wts-sc
Running for compilers: gfortran

Executing kpts-sc.x in /Users/jj/Codes/kgridGen/unittests/kpointgeneration.symmetryReduceKpointList.g49/tests
Running vasp8:  85%|██████████████████████████████████████████████████████████████████████████████████████████                | 17/20 [00:37<00:06,  2.18s/it]ERROR: 
  S  T  O  P     T  h  e     k  -  g  r  i  d     v  e  c  t  o  r  s     t  h  a  t     w  e  r  e     p  a  s  s  e  d     i  n     a  r  e     l  i  n  e  a  r  l  y     d  e  p  e  n  d  e  n  t  .
Running vasp9:  85%|██████████████████████████████████████████████████████████████████████████████████████████                | 17/20 [00:37<00:06,  2.19s/it]ERROR: 
  S  T  O  P     T  h  e     k  -  g  r  i  d     v  e  c  t  o  r  s     t  h  a  t     w  e  r  e     p  a  s  s  e  d     i  n     a  r  e     l  i  n  e  a  r  l  y     d  e  p  e  n  d  e  n  t  .
Running vasp10:  85%|█████████████████████████████████████████████████████████████████████████████████████████▎               | 17/20 [00:37<00:06,  2.19s/it]ERROR: 
  S  T  O  P     T  h  e     k  -  g  r  i  d     v  e  c  t  o  r  s     t  h  a  t     w  e  r  e     p  a  s  s  e  d     i  n     a  r  e     l  i  n  e  a  r  l  y     d  e  p  e  n  d  e  n  t  .
Running vasp10: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:37<00:00,  1.86s/it]
Checking vasp8:  75%|██████████████████████████████████████████████████████████████████████████████▊                          | 15/20 [00:00<00:00, 17.69it/s]WARNING: Model output file /Users/jj/Codes/kgridGen/tests/simple_cubic/klist.out.vasp8 does not exist for case kpts-sc.vasp8
Checking vasp9:  90%|██████████████████████████████████████████████████████████████████████████████████████████████▌          | 18/20 [00:00<00:00, 21.21it/s]WARNING: Model output file /Users/jj/Codes/kgridGen/tests/simple_cubic/klist.out.vasp9 does not exist for case kpts-sc.vasp9
Checking vasp10:  90%|█████████████████████████████████████████████████████████████████████████████████████████████▌          | 18/20 [00:00<00:00, 21.21it/s]WARNING: Model output file /Users/jj/Codes/kgridGen/tests/simple_cubic/klist.out.vasp10 does not exist for case kpts-sc.vasp10
Checking vasp10: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:00<00:00, 23.56it/s]

Executing wts-sc.x in /Users/jj/Codes/kgridGen/unittests/kpointgeneration.symmetryReduceKpointList.g49/tests
Running 10: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 62.60it/s]
Checking 10: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 922.25it/s]

RESULT: kpointgeneration.symmetryReduceKpointList | kpts-sc | gfortran 
	73.91% success (73.91% common) in 406.3150 ms

RESULT: kpointgeneration.symmetryReduceKpointList | wts-sc | gfortran 
	100.00% success (100.00% common) in 3.5150 ms

@CI: 86.96%
Failure: exiting with code 4
(BZI) src$ 

jerjorg avatar Jan 29 '18 22:01 jerjorg

This looks a bit better IMO.

    if len(error) > 0:
        if quiet:
            msg.info("With Executable at {}".format(exepath), 1)
        try:
            msg.err('\n  '+' '.join(error))
        except:
            msg.err("\n" + error[0].strip().decode("utf-8"))
(BZI) src$ runtests.py .
subroutine symmetryReduceKpointList
   COPY /users/jj/codes/kgridgen/src/generatekpoints.f90
   CASES:
     Wrote Test: kpts-sc
     Wrote Test: wts-sc
Running for compilers: gfortran

Executing kpts-sc.x in /Users/jj/Codes/kgridGen/unittests/kpointgeneration.symmetryReduceKpointList.g49/tests
Running vasp8:  85%|███████████████████████████████████████████████████████████████████████████████              | 17/20 [00:36<00:06,  2.17s/it]
ERROR: 
STOP The k-grid vectors that were passed in are linearly dependent.
Running vasp9:  85%|███████████████████████████████████████████████████████████████████████████████              | 17/20 [00:36<00:06,  2.17s/it]
ERROR: 
STOP The k-grid vectors that were passed in are linearly dependent.
Running vasp10:  85%|██████████████████████████████████████████████████████████████████████████████▏             | 17/20 [00:36<00:06,  2.17s/it]
ERROR: 
STOP The k-grid vectors that were passed in are linearly dependent.
Running vasp10: 100%|████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:36<00:00,  1.85s/it]
Checking vasp8:  75%|█████████████████████████████████████████████████████████████████████                       | 15/20 [00:00<00:00, 17.75it/s]WARNING: Model output file /Users/jj/Codes/kgridGen/tests/simple_cubic/klist.out.vasp8 does not exist for case kpts-sc.vasp8
Checking vasp9:  90%|██████████████████████████████████████████████████████████████████████████████████▊         | 18/20 [00:00<00:00, 21.29it/s]WARNING: Model output file /Users/jj/Codes/kgridGen/tests/simple_cubic/klist.out.vasp9 does not exist for case kpts-sc.vasp9
Checking vasp10:  90%|█████████████████████████████████████████████████████████████████████████████████▉         | 18/20 [00:00<00:00, 21.29it/s]WARNING: Model output file /Users/jj/Codes/kgridGen/tests/simple_cubic/klist.out.vasp10 does not exist for case kpts-sc.vasp10
Checking vasp10: 100%|███████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:00<00:00, 23.65it/s]

Executing wts-sc.x in /Users/jj/Codes/kgridGen/unittests/kpointgeneration.symmetryReduceKpointList.g49/tests
Running 10: 100%|████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 65.55it/s]
Checking 10: 100%|██████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 939.84it/s]

RESULT: kpointgeneration.symmetryReduceKpointList | kpts-sc | gfortran 
	73.91% success (73.91% common) in 390.0920 ms

RESULT: kpointgeneration.symmetryReduceKpointList | wts-sc | gfortran 
	100.00% success (100.00% common) in 3.3810 ms

@CI: 86.96%
Failure: exiting with code 4
(BZI) src$ 

jerjorg avatar Jan 29 '18 23:01 jerjorg