forked from bioconda/bioconda-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.py
More file actions
1171 lines (1052 loc) · 34.6 KB
/
test_utils.py
File metadata and controls
1171 lines (1052 loc) · 34.6 KB
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
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import subprocess as sp
import pytest
import yaml
import tempfile
import requests
import uuid
import contextlib
import tarfile
import logging
import shutil
from textwrap import dedent
from conda_build import metadata
from bioconda_utils import __version__
from bioconda_utils import utils
from bioconda_utils import pkg_test
from bioconda_utils import docker_utils
from bioconda_utils import build
from bioconda_utils import upload
from helpers import ensure_missing, Recipes
logger = logging.getLogger(__name__)
# TODO: need channel order tests. Could probably do this by adding different
# file:// channels with different variants of the same package
# Label that will be used for uploading test packages to anaconda/binstar
TEST_LABEL = 'bioconda-utils-test'
# PARAMS and ID are used with pytest.fixture. The end result is that, on Linux,
# any tests that depend on a fixture that uses PARAMS will run twice (once with
# docker, once without). On OSX, only the non-docker runs.
# Docker ref for build container
DOCKER_BASE_IMAGE = "quay.io/bioconda/bioconda-utils-test-env-cos7:latest"
SKIP_DOCKER_TESTS = sys.platform.startswith('darwin')
SKIP_NOT_OSX = not sys.platform.startswith('darwin')
if SKIP_DOCKER_TESTS:
PARAMS = [False]
IDS = ['system conda']
else:
PARAMS = [True, False]
IDS = ['with docker', 'system conda']
@contextlib.contextmanager
def ensure_env_missing(env_name):
"""
context manager that makes sure a conda env of a particular name does not
exist, deleting it if needed.
"""
def _clean():
proc = sp.run(['conda', 'env', 'list'],
stdout=sp.PIPE, stderr=sp.STDOUT, check=True,
universal_newlines=True)
if env_name in proc.stdout:
sp.run(['conda', 'env', 'remove', '-y', '-n', env_name],
stdout=sp.PIPE, stderr=sp.STDOUT, check=True,
universal_newlines=True)
_clean()
yield
_clean()
# ----------------------------------------------------------------------------
# FIXTURES
#
@pytest.fixture(scope='module')
def recipes_fixture():
"""
Writes example recipes (based on test_case.yaml), figures out the package
paths and attaches them to the Recipes instance, and cleans up afterward.
"""
rcp = Recipes('test_case.yaml')
rcp.write_recipes()
rcp.pkgs = {}
for key, val in rcp.recipe_dirs.items():
rcp.pkgs[key] = utils.built_package_paths(val)
yield rcp
for pkgs in rcp.pkgs.values():
for pkg in pkgs:
ensure_missing(pkg)
@pytest.fixture(scope='module')
def config_fixture():
"""Loads config"""
config = utils.load_config(
os.path.join(os.path.dirname(__file__), "test-config.yaml"))
yield config
@pytest.fixture(scope='module', params=PARAMS, ids=IDS)
def single_build(request, recipes_fixture):
"""
Builds the "one" recipe.
"""
if request.param:
logger.error("Making recipe builder")
docker_builder = docker_utils.RecipeBuilder(
use_host_conda_bld=True,
docker_base_image=DOCKER_BASE_IMAGE)
mulled_test = True
logger.error("DONE")
else:
docker_builder = None
mulled_test = False
logger.error("Fixture: Building 'one' %s",
"within docker" if docker_builder else "locally")
build.build(
recipe=recipes_fixture.recipe_dirs['one'],
pkg_paths=recipes_fixture.pkgs['one'],
docker_builder=docker_builder,
mulled_test=mulled_test,
)
logger.error("Fixture: Building 'one' %s -- DONE",
"within docker" if docker_builder else "locally")
yield recipes_fixture.pkgs['one']
for pkg in recipes_fixture.pkgs['one']:
ensure_missing(pkg)
@pytest.fixture(scope='module', ids=IDS)
def single_build_pkg_dir(request, recipes_fixture):
"""
Builds the "one" recipe with pkg_dir.
"""
logger.error("Making recipe builder")
docker_builder = docker_utils.RecipeBuilder(
use_host_conda_bld=True,
pkg_dir=os.getcwd() + "/output",
docker_base_image=DOCKER_BASE_IMAGE)
mulled_test = True
logger.error("DONE")
logger.error("Fixture: Building 'one' within docker with pkg_dir")
build.build(
recipe=recipes_fixture.recipe_dirs['one'],
pkg_paths=recipes_fixture.pkgs['one'],
docker_builder=docker_builder,
mulled_test=mulled_test,
)
logger.error("Fixture: Building 'one' within docker and pkg_dir -- DONE")
yield recipes_fixture.pkgs['one']
for pkg in recipes_fixture.pkgs['one']:
ensure_missing(pkg)
@pytest.fixture(scope='module', params=PARAMS, ids=IDS)
def multi_build(request, recipes_fixture, config_fixture):
"""
Builds the "one", "two", and "three" recipes.
"""
if request.param:
docker_builder = docker_utils.RecipeBuilder(
use_host_conda_bld=True,
docker_base_image=DOCKER_BASE_IMAGE)
mulled_test = True
else:
docker_builder = None
mulled_test = False
logger.error("Fixture: Building one/two/three %s",
"within docker" if docker_builder else "locally")
build.build_recipes(recipes_fixture.basedir, config_fixture,
recipes_fixture.recipe_dirnames,
docker_builder=docker_builder,
mulled_test=mulled_test)
logger.error("Fixture: Building one/two/three %s -- DONE",
"within docker" if docker_builder else "locally")
built_packages = recipes_fixture.pkgs
yield built_packages
for pkgs in built_packages.values():
for pkg in pkgs:
ensure_missing(pkg)
@pytest.fixture(scope='module')
def single_upload():
"""
Creates a randomly-named recipe and uploads it using a label so that it
doesn't affect the main bioconda channel. Tests that depend on this fixture
get a tuple of name, pakage, recipe dir. Cleans up when it's done.
"""
name = 'upload-test-' + str(uuid.uuid4()).split('-')[0]
r = Recipes(
'''
{0}:
meta.yaml: |
package:
name: {0}
version: "0.1"
'''.format(name), from_string=True)
r.write_recipes()
r.pkgs = {}
r.pkgs[name] = utils.built_package_paths(r.recipe_dirs[name])
build.build(
recipe=r.recipe_dirs[name],
pkg_paths=r.pkgs[name],
docker_builder=None,
mulled_test=False
)
pkg = r.pkgs[name][0]
upload.anaconda_upload(pkg, label=TEST_LABEL)
yield (name, pkg, r.recipe_dirs[name])
sp.run(
['anaconda', '-t', os.environ.get('ANACONDA_TOKEN'), 'remove',
'bioconda/{0}'.format(name), '--force'],
stdout=sp.PIPE, stderr=sp.STDOUT, check=True,
universal_newlines=True)
# ----------------------------------------------------------------------------
@pytest.mark.skipif(
not os.environ.get('ANACONDA_TOKEN'),
reason='No ANACONDA_TOKEN found'
)
def test_upload(single_upload):
name, pkg, recipe = single_upload
env_name = 'bioconda-utils-test-' + str(uuid.uuid4()).split('-')[0]
with ensure_env_missing(env_name):
sp.run(
['conda', 'create', '-n', env_name,
'-c', 'bioconda/label/{0}'.format(TEST_LABEL), name],
stdout=sp.PIPE, stderr=sp.STDOUT, check=True,
universal_newlines=True)
@pytest.mark.long_running_2
def test_single_build_only(single_build):
for pkg in single_build:
assert os.path.exists(pkg)
@pytest.mark.long_running_2
def test_single_build_pkg_dir(single_build):
for pkg in single_build:
assert os.path.exists(pkg)
@pytest.mark.skipif(SKIP_DOCKER_TESTS, reason='skipping on osx')
def test_single_build_with_post_test(single_build):
for pkg in single_build:
pkg_test.test_package(pkg)
@pytest.mark.long_running_1
def test_multi_build(multi_build):
for v in multi_build.values():
for pkg in v:
assert os.path.exists(pkg)
@pytest.mark.skipif(SKIP_DOCKER_TESTS, reason='skipping on osx')
def test_docker_bioconda_utils_version():
"""
Test for same bioconda-utils version in build container.
"""
docker_builder = docker_utils.RecipeBuilder(
build_script_template=('''
#! /usr/bin/env bash
python -c '
import bioconda_utils
with open("{self.container_staging}/version", "w") as version_file:
version_file.write(bioconda_utils.__version__)
'
'''
),
docker_base_image=DOCKER_BASE_IMAGE,
)
temp_dir = docker_builder.pkg_dir
# Set recipe_dir to any temporary directory, e.g., docker_builder.pkg_dir.
docker_builder.build_recipe(temp_dir, build_args='', env={})
with open(os.path.join(temp_dir, 'version')) as container_version_file:
assert container_version_file.read() == __version__
@pytest.mark.skipif(SKIP_DOCKER_TESTS, reason='skipping on osx')
def test_docker_builder_build(recipes_fixture):
"""
Tests just the build_recipe method of a RecipeBuilder object.
"""
docker_builder = docker_utils.RecipeBuilder(
use_host_conda_bld=True,
docker_base_image=DOCKER_BASE_IMAGE)
pkgs = recipes_fixture.pkgs['one']
docker_builder.build_recipe(recipes_fixture.recipe_dirs['one'],
build_args='', env={})
for pkg in pkgs:
assert os.path.exists(pkg)
@pytest.mark.skipif(SKIP_DOCKER_TESTS, reason='skipping on osx')
def test_docker_build_fails(recipes_fixture, config_fixture):
"""
Test for expected failure when a recipe fails to build
"""
docker_builder = docker_utils.RecipeBuilder(
docker_base_image=DOCKER_BASE_IMAGE,
build_script_template="exit 1")
assert docker_builder.build_script_template == 'exit 1'
result = build.build_recipes(recipes_fixture.basedir, config_fixture,
recipes_fixture.recipe_dirnames,
docker_builder=docker_builder,
mulled_test=True)
assert not result
@pytest.mark.skipif(SKIP_DOCKER_TESTS, reason='skipping on osx')
def test_docker_build_image_fails():
template = (
f"""
FROM {DOCKER_BASE_IMAGE}
RUN nonexistent command
""")
with pytest.raises(sp.CalledProcessError):
docker_utils.RecipeBuilder(dockerfile_template=template, build_image=True)
def test_get_deps():
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: 0.1
two:
meta.yaml: |
package:
name: two
version: 0.1
requirements:
build:
- one
three:
meta.yaml: |
package:
name: three
version: 0.1
requirements:
build:
- one
run:
- two
""", from_string=True)
r.write_recipes()
assert list(utils.get_deps(r.recipe_dirs['two'])) == ['one']
assert list(utils.get_deps(r.recipe_dirs['three'], build=True)) == ['one']
assert list(utils.get_deps(r.recipe_dirs['three'], build=False)) == ['two']
@pytest.mark.long_running_1
@pytest.mark.parametrize('mulled_test', PARAMS, ids=IDS)
def test_conda_as_dep(config_fixture, mulled_test):
docker_builder = None
if mulled_test:
docker_builder = docker_utils.RecipeBuilder(
use_host_conda_bld=True,
docker_base_image=DOCKER_BASE_IMAGE,
)
r = Recipes(
"""
one:
meta.yaml: |
package:
name: bioconda_utils_test_conda_as_dep
version: 0.1
requirements:
host:
- conda
run:
- conda
test:
commands:
- test -e "${PREFIX}/bin/conda"
""", from_string=True)
r.write_recipes()
build_result = build.build_recipes(
r.basedir, config_fixture,
r.recipe_dirnames,
testonly=False,
force=False,
docker_builder=docker_builder,
mulled_test=mulled_test,
)
assert build_result
for k, v in r.recipe_dirs.items():
for i in utils.built_package_paths(v):
assert os.path.exists(i)
ensure_missing(i)
# TODO replace the filter tests with tests for utils.get_package_paths()
# def test_filter_recipes_no_skipping():
# """
# No recipes have skip so make sure none are filtered out.
# """
# r = Recipes(
# """
# one:
# meta.yaml: |
# package:
# name: one
# version: "0.1"
# """, from_string=True)
# r.write_recipes()
# recipes = list(r.recipe_dirs.values())
# assert len(recipes) == 1
# filtered = list(
# utils.filter_recipes(recipes, channels=['bioconda']))
# assert len(filtered) == 1
#
#
# def test_filter_recipes_skip_is_true():
# r = Recipes(
# """
# one:
# meta.yaml: |
# package:
# name: one
# version: "0.1"
# build:
# skip: true
# """, from_string=True)
# r.write_recipes()
# recipes = list(r.recipe_dirs.values())
# filtered = list(
# utils.filter_recipes(recipes))
# print(filtered)
# assert len(filtered) == 0
#
#
# def test_filter_recipes_skip_is_true_with_CI_env_var():
# """
# utils.filter_recipes has a conditional that checks to see if there's
# a CI=true env var which in some cases only causes failure when running on
# CI. So temporarily fake it here so that local tests catch errors.
# """
# with utils.temp_env(dict(CI="true")):
# r = Recipes(
# """
# one:
# meta.yaml: |
# package:
# name: one
# version: "0.1"
# build:
# skip: true
# """, from_string=True)
# r.write_recipes()
# recipes = list(r.recipe_dirs.values())
# filtered = list(
# utils.filter_recipes(recipes))
# print(filtered)
# assert len(filtered) == 0
#
#
# def test_filter_recipes_skip_not_py27():
# """
# When all but one Python version is skipped, filtering should do that.
# """
#
# r = Recipes(
# """
# one:
# meta.yaml: |
# package:
# name: one
# version: "0.1"
# build:
# skip: True # [not py27]
# requirements:
# build:
# - python
# run:
# - python
# """, from_string=True)
# r.write_recipes()
# recipes = list(r.recipe_dirs.values())
# filtered = list(
# utils.filter_recipes(recipes, channels=['bioconda']))
#
# # one recipe, one target
# assert len(filtered) == 1
# assert len(filtered[0][1]) == 1
#
#
# def test_filter_recipes_existing_package():
# "use a known-to-exist package in bioconda"
#
# # note that we need python as a run requirement in order to get the "pyXY"
# # in the build string that matches the existing bioconda built package.
# r = Recipes(
# """
# one:
# meta.yaml: |
# package:
# name: gffutils
# version: "0.8.7.1"
# requirements:
# build:
# - python
# run:
# - python
# """, from_string=True)
# r.write_recipes()
# recipes = list(r.recipe_dirs.values())
# filtered = list(
# utils.filter_recipes(recipes, channels=['bioconda']))
# assert len(filtered) == 0
#
#
# def test_filter_recipes_force_existing_package():
# "same as above but force the recipe"
#
# # same as above, but this time force the recipe
# # TODO: refactor as py.test fixture
# r = Recipes(
# """
# one:
# meta.yaml: |
# package:
# name: gffutils
# version: "0.8.7.1"
# requirements:
# run:
# - python
# """, from_string=True)
# r.write_recipes()
# recipes = list(r.recipe_dirs.values())
# filtered = list(
# utils.filter_recipes(
# recipes, channels=['bioconda'], force=True))
# assert len(filtered) == 1
#
#
# def test_zero_packages():
# """
# Regression test; make sure filter_recipes exits cleanly if no recipes were
# provided.
# """
# assert list(utils.filter_recipes([])) == []
def test_built_package_paths():
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: "0.1"
requirements:
build:
- python 3.6
run:
- python 3.6
two:
meta.yaml: |
package:
name: two
version: "0.1"
build:
number: 0
string: ncurses{{ CONDA_NCURSES }}_{{ PKG_BUILDNUM }}
""", from_string=True)
r.write_recipes()
# Newer conda-build versions add the channel_targets and target_platform to the hash
platform = 'linux' if sys.platform == 'linux' else 'osx'
d = {"channel_targets": "bioconda main", "target_platform": "{}-64".format(platform)}
h = metadata._hash_dependencies(d, 7)
assert os.path.basename(
utils.built_package_paths(r.recipe_dirs['one'])[0]
) == 'one-0.1-py36{}_0.tar.bz2'.format(h)
def test_string_or_float_to_integer_python():
f = utils._string_or_float_to_integer_python
assert f(27) == f('27') == f(2.7) == f('2.7') == 27
def test_rendering_sandboxing():
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: 0.1
extra:
var: {{ GITHUB_TOKEN }}
""", from_string=True)
r.write_recipes()
env = {
# None of these should be passed to the recipe
'CONDA_ARBITRARY_VAR': 'conda-val-here',
'TRAVIS_ARBITRARY_VAR': 'travis-val-here',
'GITHUB_TOKEN': 'asdf',
'BUILDKITE_TOKEN': 'asdf',
}
# If GITHUB_TOKEN is already set in the bash environment, then we get
# a message on stdout+stderr (this is the case on travis-ci).
#
# However if GITHUB_TOKEN is not already set in the bash env (e.g., when
# testing locally), then we get a SystemError.
#
# In both cases we're passing in the `env` dict, which does contain
# GITHUB_TOKEN.
if 'GITHUB_TOKEN' in os.environ:
with pytest.raises(sp.CalledProcessError) as excinfo:
pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])
build.build(
recipe=r.recipe_dirs['one'],
pkg_paths=pkg_paths,
mulled_test=False,
raise_error=True,
)
assert ("'GITHUB_TOKEN' is undefined" in str(excinfo.value.stdout))
else:
# recipe for "one" should fail because GITHUB_TOKEN is not a jinja var.
with pytest.raises(SystemExit) as excinfo:
pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])
build.build(
recipe=r.recipe_dirs['one'],
pkg_paths=pkg_paths,
mulled_test=False,
)
assert "'GITHUB_TOKEN' is undefined" in str(excinfo.value)
def test_sandboxed():
env = {
'PATH': '/foo/bar',
'CONDA_ARBITRARY_VAR': 'conda-val-here',
'TRAVIS_ARBITRARY_VAR': 'travis-val-here',
'GITHUB_TOKEN': 'asdf',
'BUILDKITE_TOKEN': 'asdf',
}
with utils.sandboxed_env(env):
print(os.environ)
assert os.environ['PATH'] == '/foo/bar'
assert 'CONDA_ARBITRARY_VAR' not in os.environ
assert 'TRAVIS_ARBITRARY_VAR' not in os.environ
assert 'GITHUB_TOKEN' not in os.environ
assert 'BUILDKITE_TOKEN' not in os.environ
def test_env_sandboxing():
r = Recipes(
r"""
one:
meta.yaml: |
package:
name: one
version: 0.1
build.sh: |
#!/bin/bash
if [[ -z $GITHUB_TOKEN ]]
then
exit 0
else
echo "\$GITHUB_TOKEN has leaked into the build environment!"
exit 1
fi
""", from_string=True)
r.write_recipes()
pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])
with utils.temp_env({'GITHUB_TOKEN': 'token_here'}):
build.build(
recipe=r.recipe_dirs['one'],
pkg_paths=pkg_paths,
mulled_test=False
)
for pkg in pkg_paths:
assert os.path.exists(pkg)
ensure_missing(pkg)
def test_skip_dependencies(config_fixture):
r = Recipes(
"""
one:
meta.yaml: |
package:
name: skip_dependencies_one
version: 0.1
two:
meta.yaml: |
package:
name: skip_dependencies_two
version: 0.1
requirements:
build:
- skip_dependencies_one
- nonexistent
three:
meta.yaml: |
package:
name: skip_dependencies_three
version: 0.1
requirements:
build:
- skip_dependencies_one
run:
- skip_dependencies_two
""", from_string=True)
r.write_recipes()
pkgs = {}
for k, v in r.recipe_dirs.items():
pkgs[k] = utils.built_package_paths(v)
for _pkgs in pkgs.values():
for pkg in _pkgs:
ensure_missing(pkg)
build.build_recipes(r.basedir, config_fixture,
r.recipe_dirnames,
testonly=False,
force=False,
mulled_test=False)
for pkg in pkgs['one']:
assert os.path.exists(pkg)
for pkg in pkgs['two']:
assert not os.path.exists(pkg)
for pkg in pkgs['three']:
assert not os.path.exists(pkg)
# clean up
for _pkgs in pkgs.values():
for pkg in _pkgs:
ensure_missing(pkg)
class TestSubdags(object):
def _build(self, recipes_fixture, config_fixture, n_workers, worker_offset):
build.build_recipes(recipes_fixture.basedir, config_fixture,
recipes_fixture.recipe_dirnames,
n_workers=n_workers, worker_offset=worker_offset,
mulled_test=False)
def test_subdags_out_of_range(self, recipes_fixture, config_fixture):
with pytest.raises(ValueError):
self._build(recipes_fixture, config_fixture, 2, 4)
@pytest.mark.skipif(SKIP_DOCKER_TESTS, reason='skipping on osx')
def test_build_empty_extra_container():
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: 0.1
extra:
container:
# empty
""", from_string=True)
r.write_recipes()
pkgs = utils.built_package_paths(r.recipe_dirs['one'])
build_result = build.build(
recipe=r.recipe_dirs['one'],
pkg_paths=pkgs,
mulled_test=True,
)
assert build_result.success
for pkg in pkgs:
assert os.path.exists(pkg)
ensure_missing(pkg)
@pytest.mark.skipif(SKIP_DOCKER_TESTS, reason='skipping on osx')
@pytest.mark.long_running_1
@pytest.mark.xfail
def test_build_container_no_default_gcc(tmpdir):
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: 0.1
test:
commands:
- gcc --version
""", from_string=True)
r.write_recipes()
# Tests with the repository's Dockerfile instead of already uploaded images.
# Copy repository to image build directory so everything is in docker context.
image_build_dir = os.path.join(tmpdir, "repo")
src_repo_dir = os.path.join(os.path.dirname(__file__), "..")
shutil.copytree(src_repo_dir, image_build_dir)
# Dockerfile will be recreated by RecipeBuilder => extract template and delete file
dockerfile = os.path.join(image_build_dir, "Dockerfile")
with open(dockerfile) as f:
dockerfile_template = f.read().replace("{", "{{").replace("}", "}}")
os.remove(dockerfile)
docker_builder = docker_utils.RecipeBuilder(
dockerfile_template=dockerfile_template,
use_host_conda_bld=True,
image_build_dir=image_build_dir,
)
pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])
build_result = build.build(
recipe=r.recipe_dirs['one'],
pkg_paths=pkg_paths,
docker_builder=docker_builder,
mulled_test=False,
)
assert build_result.success
for k, v in r.recipe_dirs.items():
for i in utils.built_package_paths(v):
assert os.path.exists(i)
ensure_missing(i)
# FIXME: This test fails erraticaly. Both in built_package_paths
# and in build_recipes, the generated name can be either
# one-0.1-h1341992_0.tar.bz2 or one-0.1-0.tar.bz2 - which
# appears to be mostly random.
def no_test_conda_forge_pins(caplog, config_fixture):
caplog.set_level(logging.DEBUG)
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: 0.1
requirements:
run:
- zlib {{ zlib }}
""", from_string=True)
r.write_recipes()
build_result = build.build_recipes(r.basedir, config_fixture,
r.recipe_dirnames,
testonly=False,
force=False,
mulled_test=False)
assert build_result
for k, v in r.recipe_dirs.items():
for i in utils.built_package_paths(v):
print(os.listdir(os.path.dirname(i)))
assert os.path.exists(i)
ensure_missing(i)
def test_bioconda_pins(caplog, config_fixture):
"""
htslib currently only provided by bioconda pinnings
"""
caplog.set_level(logging.DEBUG)
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: 0.1
requirements:
run:
- htslib
""", from_string=True)
r.write_recipes()
build_result = build.build_recipes(r.basedir, config_fixture,
r.recipe_dirnames,
testonly=False,
force=False,
mulled_test=False)
assert build_result
for k, v in r.recipe_dirs.items():
for i in utils.built_package_paths(v):
assert os.path.exists(i)
ensure_missing(i)
def test_load_meta_skipping():
"""
Ensure that a skipped recipe returns no metadata
"""
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: "0.1"
build:
skip: true
""", from_string=True)
r.write_recipes()
recipe = r.recipe_dirs['one']
assert utils.load_all_meta(recipe) == []
def test_variants():
"""
Multiple variants should return multiple metadata
"""
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: "0.1"
requirements:
build:
- mypkg {{ mypkg }}
""", from_string=True)
r.write_recipes()
recipe = r.recipe_dirs['one']
# Write a temporary conda_build_config.yaml that we'll point the config
# object to:
tmp = tempfile.NamedTemporaryFile(delete=False).name
with open(tmp, 'w') as fout:
fout.write(
dedent(
"""
mypkg:
- 1.0
- 2.0
"""))
config = utils.load_conda_build_config()
config.exclusive_config_files = [tmp]
assert len(utils.load_all_meta(recipe, config)) == 2
@pytest.mark.long_running_2
def test_cb3_outputs(config_fixture):
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: "0.1"
outputs:
- name: libone
- name: py-one
requirements:
- {{ pin_subpackage('libone', exact=True) }}
- python {{ python }}
""", from_string=True)
r.write_recipes()
r.recipe_dirs['one']
build_result = build.build_recipes(r.basedir, config_fixture,
r.recipe_dirnames,
testonly=False,
force=False,
mulled_test=False)
assert build_result
for k, v in r.recipe_dirs.items():
for i in utils.built_package_paths(v):
assert os.path.exists(i)
ensure_missing(i)
@pytest.mark.long_running_2
def test_compiler(config_fixture):
r = Recipes(
"""
one:
meta.yaml: |
package:
name: one
version: 0.1
requirements:
build: