|  | 1 | +#
 | 
|  | 2 | +#  Copyright (C) 2018 Bloomberg Finance LP
 | 
|  | 3 | +#
 | 
|  | 4 | +#  This program is free software; you can redistribute it and/or
 | 
|  | 5 | +#  modify it under the terms of the GNU Lesser General Public
 | 
|  | 6 | +#  License as published by the Free Software Foundation; either
 | 
|  | 7 | +#  version 2 of the License, or (at your option) any later version.
 | 
|  | 8 | +#
 | 
|  | 9 | +#  This library is distributed in the hope that it will be useful,
 | 
|  | 10 | +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|  | 11 | +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
|  | 12 | +#  Lesser General Public License for more details.
 | 
|  | 13 | +#
 | 
|  | 14 | +#  You should have received a copy of the GNU Lesser General Public
 | 
|  | 15 | +#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 | 
|  | 16 | +#
 | 
|  | 17 | +#  Authors: Chandan Singh <csingh43 bloomberg net>
 | 
|  | 18 | +#
 | 
|  | 19 | +
 | 
|  | 20 | +import os
 | 
|  | 21 | +import tarfile
 | 
|  | 22 | +
 | 
|  | 23 | +import pytest
 | 
|  | 24 | +
 | 
|  | 25 | +from tests.testutils import cli
 | 
|  | 26 | +
 | 
|  | 27 | +# Project directory
 | 
|  | 28 | +DATA_DIR = os.path.join(
 | 
|  | 29 | +    os.path.dirname(os.path.realpath(__file__)),
 | 
|  | 30 | +    "project",
 | 
|  | 31 | +)
 | 
|  | 32 | +
 | 
|  | 33 | +
 | 
|  | 34 | +@pytest.mark.datafiles(DATA_DIR)
 | 
|  | 35 | +def test_source_bundle(cli, tmpdir, datafiles):
 | 
|  | 36 | +    project_path = os.path.join(datafiles.dirname, datafiles.basename)
 | 
|  | 37 | +    element_name = 'source-bundle/source-bundle-hello.bst'
 | 
|  | 38 | +    normal_name = 'source-bundle-source-bundle-hello'
 | 
|  | 39 | +
 | 
|  | 40 | +    # Verify that we can correctly produce a source-bundle
 | 
|  | 41 | +    args = ['source-bundle', element_name, '--directory', str(tmpdir)]
 | 
|  | 42 | +    result = cli.run(project=project_path, args=args)
 | 
|  | 43 | +    result.assert_success()
 | 
|  | 44 | +
 | 
|  | 45 | +    # Verify that the source-bundle contains our sources and a build script
 | 
|  | 46 | +    with tarfile.open(os.path.join(str(tmpdir), '{}.tar.gz'.format(normal_name))) as bundle:
 | 
|  | 47 | +        assert os.path.join(normal_name, 'source', normal_name, 'llamas.txt') in bundle.getnames()
 | 
|  | 48 | +        assert os.path.join(normal_name, 'build.sh') in bundle.getnames() |