-
Notifications
You must be signed in to change notification settings - Fork 16
/
pavement.py
804 lines (616 loc) · 17.8 KB
/
pavement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
"""
Quantarhei Package Tests
========================
To run the tests, the following packages have to be installed
paver (pip install paver)
nose (pip install nose)
aloe (pip install aloe)
behave (pip install behave)
pylint (pip install pylint)
About our tests
---------------
Quantarhei is tested against unit tests run by the `nose` tool, against
acceptance tests run by `aloe` tool and against doc tests (run by `nose`).
We also calculate coverege using the `coverage` tool and we plan to
check the code by `pylint`.
The ultimit goal of testing in 100 % coverage and perfect code style.
The following tasks are available. Run them with `paver` as
.. code:: bash
$ paver TASK_NAME
To test the whole suit, just run `paver` without any task.
.. code:: bash
$ paver
Doctest Tasks
-------------
doc_tests
doc_tests_v
doc_tests_vs
doc_tests_cov
doc_tests_cov_v
doc_tests_cov_vs
Runs test doc tests. _cov means `--with-coverage` option, _v means
with `-v` option for verbose output and _vs means with `-vs` option, i.e.
verbose and printing standard output of the tests.
Unit tests
----------
unit_tests_vs
unit_tests_cov_vs
Acceptance tests
----------------
aloe_tests_vs
aloe_tests_cov_vs
Tests to be run during development
----------------------------------
doc_dev
unit_dev
Edit the list of files or directories that you want to test during
development.
"""
import contextlib
import os
import subprocess
import platform
from paver.tasks import task
from paver.tasks import needs
from paver.easy import sh
""" The project version has to be set here and then in the following files:
Makefile
docs/sphinx/conf.py
quantarhei/core/managers.py
setup.py
Ideally it would be all updated base on the present file by calling:
> paver version-update
"""
version = "0.0.66"
sys_name = platform.system()
pip = 'pip'
python = 'python'
#
# Commands for deleting files and directories silently and without error codes
#
if sys_name == "Darwin" or sys_name == "Linux":
deldir = 'rm -r -f '
delfile = 'rm -r -f '
elif sys_name == "Windows":
deldir = 'rmdir /s /q '
delfile = 'del /s /q '
else:
raise Exception("Unknown system")
#
# The Mother of all repositories
#
repository = 'https://github.com/tmancal74/quantarhei'
#
# look for location of `behave`
#
if sys_name != "Windows":
p = subprocess.Popen('which behave', shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ii = 0
for line in p.stdout.readlines():
behave_bin = str(line.decode())
behave_bin = behave_bin.strip()
ii += 1
if ii != 1:
raise Exception("Don't know where `behave` is")
else:
behave_bin = "behave"
#
# Context manager for getting into subdirectories
#
@contextlib.contextmanager
def cd(path):
old_path = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(old_path)
def rm_rf(path):
"""Removal of files and directories, recursively and silently
"""
pass
#
###############################################################################
#
# Standard developer tasks
#
###############################################################################
#
###############################################################################
# Creates distribution
###############################################################################
@task
def sdist():
sh(python+" setup.py sdist")
###############################################################################
# Installs Quantarhei from the source
###############################################################################
@needs('sdist')
@task
def inst():
sh(pip+' install dist/quantarhei-'+version+'.tar.gz')
#
# The same as above
#
@needs('inst')
@task
def install():
pass
###############################################################################
# Uninstall local installation of Quantarhei
###############################################################################
@needs('uninst')
@task
def uninstall():
pass
#
# The same as above
#
@task
def uninst():
sh(pip+' uninstall -y quantarhei')
###############################################################################
# Upload to pypi
###############################################################################
@needs('sdist')
@task
def upload():
sh('twine upload dist/quantarhei-'+version+'.tar.gz')
###############################################################################
# Clean-up
###############################################################################
@task
def clean():
try:
sh(deldir+'dist')
except:
print("Directory not present - no problem")
try:
sh(delfile+'quantarhei.egg-info')
except:
print("File not present - no problem")
try:
sh(deldir+'result_images')
except:
print("Directory not present - no problem")
try:
sh(delfile+'qrconf.py quantarhei/qrconf.py')
except:
print("File not present - no problem")
try:
sh(delfile+'test.log')
except:
print("File not present - no problem")
###############################################################################
# Reinstallation with clean-up
###############################################################################
@needs('clean','uninst', 'inst')
@task
def reinst():
pass
###############################################################################
# Local tests: this will reinstall Quantarhei and run tests
###############################################################################
@needs('reinst')
@task
def local_tests():
sh('paver')
###############################################################################
# Test of plotting
###############################################################################
@needs('matplotlib_tests')
@task
def plot_tests():
pass
###############################################################################
# Update examples
###############################################################################
@task
def update_examples():
sh('cd examples; python admin/make_demos.py')
###############################################################################
#
###############################################################################
@task
def tasks():
print("")
print("Quantarhei Paver Tasks")
print("======================")
print("")
print("Essential tasks: ")
print("----------------")
print("inst ... install quantarhei from this source code")
print("reinst ... uninstall and install from this source code")
print("local_tests ... uninstall, install and run tests")
print("plot_tests ... run tests of plotting")
print("test ... run tests")
print("sdist ... create distribution")
print("clean ... clean the repository")
print("examples ... updates examples")
print("")
print("Git tasks: ")
print("----------")
print("git_add_upstream, git_update_master")
print("")
###############################################################################
# Helper tasks for managing pull-requests
###############################################################################
#
# update from master branch of the quantarhei's main repository
#
@task
def git_update_master():
sh('git fetch upstream')
sh('git checkout master')
sh('git merge upstream/master')
###############################################################################
# connect a forked local repository to the main quantarhei repository
###############################################################################
@task
def git_add_upstream():
sh('git remote add upstream '+repository)
###############################################################################
#
# Graphical output testing
#
###############################################################################
#
# TASK: matplotlib_tests
#
@task
def matplotlib_tests():
"""Tests matplotlib output
This test seems not to work on all platforms.
!!!Currently it is not run in automatic build testing!!!
"""
sh('cd tests/matplotlib; ./tests.py; cd ..')
#
# TASK: remove .coverage
#
@task
def coverage_erase():
""" Remove coverage from previous build
"""
sh('coverage erase')
#
# TASK: combine coverage reports
#
@task
def coverage_combine():
""" Combines all coverage reports into one
"""
sh('coverage combine --append')
###############################################################################
#
# Tests of Quantarhei installed examples
#
###############################################################################
cover_flags = '--cover-package=quantarhei '
covr = ' --with-coverage '
nose_test_dir = 'tests/unit/wizard/examples/ '
#
# TASK: examples
#
@task
def examples():
"""Tests if Quantarhei examples run correctly
"""
sh('coverage run -m nose -vs '+covr+cover_flags+nose_test_dir)
###############################################################################
#
# Unit tests
#
###############################################################################
nose_test_dir = 'tests/unit'
#
# TASK: unit_tests_vs
#
@task
def unit_tests_vs():
"""Performs verbose units tests printing output but without coverage
"""
sh('nosetests -vs '+cover_flags+nose_test_dir)
#
# TASK: unit_tests_v
#
@task
def unit_tests_v():
"""Performs verbose units tests capturing output but without coverage
"""
sh('nosetests -v '+cover_flags+nose_test_dir)
#
# TASK: unit_tests_cov_vs
#
@task
def unit_tests_cov_vs():
"""Performs verbose units tests without capturing output and with coverage
"""
sh('nosetests -vs '+covr+cover_flags+nose_test_dir)
#
# TASK: unit_tests_cov_v
#
@task
def unit_tests_cov_v():
"""Performs verbose units tests capturing output and with coverage
"""
sh('nosetests -v '+covr+cover_flags+nose_test_dir)
###############################################################################
#
# Doc tests
#
###############################################################################
# Doc tests with coverage
cmdd = 'nosetests --with-doctest'
# Directories to test
dirs = ['core', 'builders', 'qm/corfunctions', 'spectroscopy',
'qm/liouvillespace', 'functions', 'qm/hilbertspace', 'qm/propagators']
# Specific modules to test
mods = ['qm/propagators/poppropagator.py']
#
# TASK: doc_tests_cov_vs
#
@task
def doc_tests_cov_vs():
"""Verbose doc test with coverage
This test runs with coverage in a verbose mode. Output is not captured
but printed to the screen.
Run it as
.. code:: bash
paver doc_tests_cov_vs
"""
tcmd = cmdd+covr+' -vs '+cover_flags
_run_tests(tcmd, mods, dirs)
#
# TASK: doc_tests_cov_vs
#
@task
def doc_tests_cov_v():
"""Verbose doc test with coverage
This test runs with coverage in a verbose mode. Output is captured.
Run it as
.. code:: bash
paver doc_tests_cov_v
"""
tcmd = cmdd+covr+' -v '+cover_flags
_run_tests(tcmd, mods, dirs)
#
# TASK: doc_tests_vs
#
@task
def doc_tests_vs():
"""Verbose doc test without coverage
This test runs without coverage in a verbose mode. Output is not captured
but printed to the screen.
Run it as
.. code:: bash
paver doc_tests_vs
"""
tcmd = cmdd+' -vs '+cover_flags
_run_tests(tcmd, mods, dirs)
#
# TASK: doc_tests_vs
#
@task
def doc_tests_v():
"""Verbose doc test without coverage, capturing the output
This test runs without coverage in a verbose mode. Output is captured.
Run it as
.. code:: bash
paver doc_tests_v
"""
tcmd = cmdd+' -v '+cover_flags
_run_tests(tcmd, mods, dirs)
def _run_tests(tcmd, dirs, mods):
"""Runs tests on directories and modules
"""
# run on directories
for _dir in dirs:
sh(tcmd+"quantarhei/"+_dir)
# run on modules
for _mod in mods:
sh(tcmd+"quantarhei/"+_mod)
###############################################################################
#
# Aloe tests
#
###############################################################################
aloe_test_dir = 'tests/bdd'
@task
def aloe_tests_vs():
sh("aloe -vs -a !in_development "+cover_flags+aloe_test_dir)
@task
def aloe_tests_v():
sh("aloe -v -a !in_development "+cover_flags+aloe_test_dir)
@task
def aloe_tests_cov_vs():
sh("aloe --with-coverage -vs -a !in_development "+cover_flags+aloe_test_dir)
@task
def aloe_tests_cov_v():
sh('aloe --with-coverage -v -a !in_development '+cover_flags+aloe_test_dir)
###############################################################################
#
# Behave tests
#
###############################################################################
@task
def behave():
path = os.path.join('.','tests', 'behave', 'features')
sh("coverage run "+behave_bin+" "+path)
###############################################################################
#
# Documentation build test
#
###############################################################################
#
# TASK: html
#
@task
def html():
sh('cd docs/sphinx/; make html')
#
# TASK: html_clean
#
@task
def html_clean():
sh('cd docs/sphinx/; make clean')
###############################################################################
#
# Pylint tests
#
###############################################################################
class Runner:
"""Class to run pylint tests
"""
def __init__(self,path):
self.path = path
def set_path(self,path):
self.path = path
def un(self,file):
rcfile = 'tests/pylint/pylintrc'
sh('pylint --rcfile='+rcfile+' '+self.path+'/'+file)
@task
def pylint():
"""Runs pylint tests on specified files
"""
path = 'quantarhei/core/'
r = Runner(path)
# r.un('valueaxis.py')
# r.un('time.py')
# r.un('frequency.py')
# r.un('dfunction.py')
path = 'quantarhei/qm/corfunctions'
r.set_path(path)
# r.un('correlationfunctions.py')
# r.un('spectraldensities.py')
# r.un('cfmatrix.py')
path = 'quantarhei/qm/hilbertspace'
r.set_path(path)
# r.un('statevector.py')
# r.un('aggregate_test.py')
path = 'quantarhei/qm/liouvillespace'
r.set_path(path)
# r.un('lindbladform.py')
path = 'quantarhei/builders'
r.set_path(path)
# r.un('pdb.py')
path = 'quantarhei/core'
r.set_path(path)
#r.un('matrixdata.py')
#r.un('saveable.py')
path = 'quantarhei/utils/'
r.set_path(path)
# r.un('logging.py')
path = 'quantarhei/scripts/'
r.set_path(path)
#r.un('ghenerate.py')
r.un('qrhei.py')
###############################################################################
#
# Development tasks
#
# Edit this if you need to test only particular part
# of the code which you develop. Then maybe ignore this file during commits
#
###############################################################################
#
# Targets for doc tests
#
doc_devs = ['quantarhei/spectroscopy/twod2.py',
'quantarhei/qm/liouvillespace',
'quantarhei/functions']
#
# Targets for unit tests
#
unit_devs = ['tests/unit/qm/liouvillespace/test_evolutionsuperoperator.py',
'tests/unit/qm/propagators/rdmpropagator_test.py']
cmd = 'nosetests'
doct = ' --with-doctest'
#
# TASK: doc_dev
#
@task
def doc_dev():
"""Task to run doctests on files under development
"""
tcmd = cmd+doct+' -vs '
for _dev in doc_devs:
sh(tcmd+_dev)
#
# TASK: unit_dev
#
@task
def unit_dev():
"""Task to run unit tests on files under development
"""
tcmd = cmd+' -vs '
for _dev in unit_devs:
sh(tcmd+_dev)
###############################################################################
#
# Codecov (upload of coverage results to codecov.io server)
#
###############################################################################
#
# TASK: codecov
#
@task
def codecov():
"""Uploads the results of `coverage` command on the codecov.io server
"""
sh('codecov --token=1d501d6b-b32d-44c2-8253-8b12ef3c8cc9')
###############################################################################
#
# Collections of tests including default test task
#
###############################################################################
# Removing matplotlib tests because it does not work on remote travis CI
#@needs('matplotlib_tests',
# 'unit_tests_cov_vs',
# 'doc_tests_cov_vs',
# 'aloe_tests_cov_vs',
# 'pylint')
#
# This is called when paver is run without any task
#
#@needs('unit_tests_cov_v',
# 'doc_tests_cov_v',
# 'aloe_tests_cov_v',
# 'behave')
@needs('test')
@task
def default():
"""Default paver task
"""
pass
#
# This is called when paver is run without any task
#
#@needs('coverage_erase',
# 'unit_tests_cov_v',
# 'doc_tests_cov_v',
# 'aloe_tests_cov_v',
# 'behave')
@needs('coverage_erase',
'unit_tests_cov_v',
'doc_tests_cov_v',
'aloe_tests_cov_v',
'behave',
'coverage_combine')
@task
def test():
"""Default paver task
"""
pass
#
# Verbose version of the default tests
#
@needs('coverage_erase',
'unit_tests_cov_vs',
'doc_tests_cov_vs',
'aloe_tests_cov_vs')
@task
def verbose():
"""Run the default tests but with printing output
"""
pass