Ejemplo n.º 1
0
    def test_schema_catches_missing_destination(self):
        with testtools.ExpectedException(jsonschema.exceptions.ValidationError,
                                         ".*None is not of type 'string'.*"):
            jsonschema.validate({'files': {'foo': None}}, CopyPlugin.schema())

        with testtools.ExpectedException(jsonschema.exceptions.ValidationError,
                                         ".*'' is too short.*"):
            jsonschema.validate({'files': {'foo': ''}}, CopyPlugin.schema())
Ejemplo n.º 2
0
    def test_copy_plugin_copies(self):
        self.mock_options.files = {
            'src': 'dst',
        }
        open('src', 'w').close()

        c = CopyPlugin('copy', self.mock_options)
        c.build()
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, 'dst')))
Ejemplo n.º 3
0
    def test_copy_plugin_copies(self):
        self.mock_options.files = {
            'src': 'dst',
        }
        open('src', 'w').close()

        c = CopyPlugin('copy', self.mock_options)
        c.build()
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, 'dst')))
Ejemplo n.º 4
0
    def test_schema_catches_missing_destination(self):
        with testtools.ExpectedException(
                jsonschema.exceptions.ValidationError,
                ".*None is not of type 'string'.*"):
            jsonschema.validate({'files': {'foo': None}}, CopyPlugin.schema())

        with testtools.ExpectedException(
                jsonschema.exceptions.ValidationError,
                ".*'' is too short.*"):
            jsonschema.validate({'files': {'foo': ''}}, CopyPlugin.schema())
Ejemplo n.º 5
0
    def test_copy_plugin_handles_dot(self):
        self.mock_options.files = {
            'src': '.',
        }
        open('src', 'w').close()

        c = CopyPlugin('copy', self.mock_options, self.project_options)
        c.pull()
        c.build()
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, 'src')))
Ejemplo n.º 6
0
    def test_copy_glob_does_not_match_anything(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {"src*": "dst"}
        c = CopyPlugin("copy", self.mock_options, self.project_options)
        c.pull()

        raised = self.assertRaises(errors.SnapcraftEnvironmentError, c.build)

        self.assertThat(raised.__str__(), Equals("no matches for 'src*'"))
Ejemplo n.º 7
0
    def test_copy_plugin_handles_leading_slash(self):
        self.mock_options.files = {
            'src': '/dst',
        }
        open('src', 'w').close()

        c = CopyPlugin('copy', self.mock_options)
        c.pull()
        c.build()
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, 'dst')))
Ejemplo n.º 8
0
    def test_copy_glob_does_not_match_anything(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {"src*": "dst"}
        c = CopyPlugin("copy", self.mock_options, self.project_options)
        c.pull()

        raised = self.assertRaises(errors.SnapcraftEnvironmentError, c.build)

        self.assertThat(raised.__str__(), Equals("no matches for 'src*'"))
Ejemplo n.º 9
0
    def test_copy_plugin_any_missing_src_raises_exception(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {"src": "dst", "zzz": "zzz"}
        open("zzz", "w").close()
        c = CopyPlugin("copy", self.mock_options, self.project_options)
        c.pull()

        raised = self.assertRaises(errors.SnapcraftCopyFileNotFoundError, c.build)
        self.assertThat(raised.path, Equals(os.path.join(c.builddir, "src")))
Ejemplo n.º 10
0
    def test_copy_plugin_copies(self):
        self.useFixture(fixtures.FakeLogger())

        self.mock_options.files = {
            "src": "dst",
        }
        open("src", "w").close()

        c = CopyPlugin("copy", self.mock_options)
        c.build()
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, "dst")))
Ejemplo n.º 11
0
    def test_copy_plugin_any_missing_src_raises_exception(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {"src": "dst", "zzz": "zzz"}
        open("zzz", "w").close()
        c = CopyPlugin("copy", self.mock_options, self.project_options)
        c.pull()

        raised = self.assertRaises(errors.SnapcraftCopyFileNotFoundError,
                                   c.build)
        self.assertThat(raised.path, Equals(os.path.join(c.builddir, "src")))
Ejemplo n.º 12
0
    def test_copy_directories(self):
        self.mock_options.files = {
            'dirs1': 'dir/dst',
        }
        os.mkdir('dirs1')
        file = os.path.join('dirs1', 'f')
        open(file, 'w').close()

        c = CopyPlugin('copy', self.mock_options)
        c.build()
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, 'dir', 'dst', 'f')))
Ejemplo n.º 13
0
    def test_copy_plugin_creates_prefixes(self):
        self.useFixture(fixtures.FakeLogger())

        self.mock_options.files = {
            'src': 'dir/dst',
        }
        open('src', 'w').close()

        c = CopyPlugin('copy', self.mock_options)
        c.build()
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, 'dir/dst')))
Ejemplo n.º 14
0
    def test_copy_glob_does_not_match_anything(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {
            'src*': 'dst',
        }
        c = CopyPlugin('copy', self.mock_options, self.project_options)
        c.pull()

        raised = self.assertRaises(EnvironmentError, c.build)

        self.assertEqual(raised.__str__(), "no matches for 'src*'")
Ejemplo n.º 15
0
    def test_copy_directories(self):
        self.mock_options.files = {
            'dirs1': 'dir/dst',
        }
        os.mkdir('dirs1')
        file = os.path.join('dirs1', 'f')
        open(file, 'w').close()

        c = CopyPlugin('copy', self.mock_options)
        c.build()
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, 'dir', 'dst', 'f')))
Ejemplo n.º 16
0
    def test_copy_plugin_creates_prefixes(self):
        self.useFixture(fixtures.FakeLogger())

        self.mock_options.files = {
            'src': 'dir/dst',
        }
        open('src', 'w').close()

        c = CopyPlugin('copy', self.mock_options)
        c.build()
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix,
                                                    'dir/dst')))
Ejemplo n.º 17
0
    def test_copy_plugin_handles_leading_slash(self):
        self.mock_options.files = {"src": "/dst"}
        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        open(os.path.join(c.builddir, "src"), "w").close()

        c.build()

        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, "dst")))
Ejemplo n.º 18
0
    def test_copy_plugin_handles_leading_slash(self):
        self.mock_options.files = {"src": "/dst"}
        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        open(os.path.join(c.builddir, "src"), "w").close()

        c.build()

        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, "dst")))
Ejemplo n.º 19
0
    def test_copy_glob_does_not_match_anything(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {
            'src*': 'dst',
        }
        c = CopyPlugin('copy', self.mock_options, self.project_options)
        c.pull()

        raised = self.assertRaises(EnvironmentError, c.build)

        self.assertEqual(raised.__str__(), "no matches for 'src*'")
Ejemplo n.º 20
0
    def test_copy_symlinks_that_should_be_followed(self):
        self.mock_options.files = {'foo/*': '.'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, 'foo', 'bar'))
        with open(os.path.join(c.builddir, 'foo', 'file'), 'w') as f:
            f.write('foo')

        with open('unsnapped', 'w') as f:
            f.write('bar')

        symlinks = [
            # Links with an absolute path should be followed
            {
                'source': os.path.join(c.builddir, 'foo', 'file'),
                'link_name': os.path.join(c.builddir, 'foo', 'absolute'),
                'destination': os.path.join(c.installdir, 'absolute'),
                'expected_contents': 'foo',
            },
            # Links with a relative path that points outside of the snap
            # should also be followed
            {
                'source': '../../../../unsnapped',
                'link_name': os.path.join(c.builddir, 'foo', 'bad_relative'),
                'destination': os.path.join(c.installdir, 'bad_relative'),
                'expected_contents': 'bar',
            },
        ]

        for symlink in symlinks:
            os.symlink(symlink['source'], symlink['link_name'])

        c.build()

        with open(os.path.join(c.installdir, 'file'), 'r') as f:
            self.assertEqual(f.read(), 'foo')

        for symlink in symlinks:
            destination = symlink['destination']
            with self.subTest('link: {}'.format(destination)):
                self.assertFalse(
                    os.path.islink(destination),
                    'Expected {!r} to be a copy rather than a '
                    'symlink'.format(destination))

                with open(destination, 'r') as f:
                    self.assertEqual(f.read(), symlink['expected_contents'])
Ejemplo n.º 21
0
    def test_copy_symlinks_that_should_be_followed(self):
        self.mock_options.files = {"foo/*": "."}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, "foo", "bar"))
        with open(os.path.join(c.builddir, "foo", "file"), "w") as f:
            f.write("foo")

        with open("unsnapped", "w") as f:
            f.write("bar")

        symlinks = [
            # Links with an absolute path should be followed
            {
                "source": os.path.join(c.builddir, "foo", "file"),
                "link_name": os.path.join(c.builddir, "foo", "absolute"),
                "destination": os.path.join(c.installdir, "absolute"),
                "expected_contents": "foo",
            },
            # Links with a relative path that points outside of the snap
            # should also be followed
            {
                "source": "../../../../unsnapped",
                "link_name": os.path.join(c.builddir, "foo", "bad_relative"),
                "destination": os.path.join(c.installdir, "bad_relative"),
                "expected_contents": "bar",
            },
        ]

        for symlink in symlinks:
            os.symlink(symlink["source"], symlink["link_name"])

        c.build()

        with open(os.path.join(c.installdir, "file"), "r") as f:
            self.assertThat(f.read(), Equals("foo"))

        for symlink in symlinks:
            destination = symlink["destination"]
            self.assertFalse(
                os.path.islink(destination),
                "Expected {!r} to be a copy rather than a "
                "symlink".format(destination),
            )

            with open(destination, "r") as f:
                self.assertThat(f.read(), Equals(symlink["expected_contents"]))
Ejemplo n.º 22
0
    def test_copy_symlinks_that_should_be_followed(self):
        self.mock_options.files = {"foo/*": "."}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, "foo", "bar"))
        with open(os.path.join(c.builddir, "foo", "file"), "w") as f:
            f.write("foo")

        with open("unsnapped", "w") as f:
            f.write("bar")

        symlinks = [
            # Links with an absolute path should be followed
            {
                "source": os.path.join(c.builddir, "foo", "file"),
                "link_name": os.path.join(c.builddir, "foo", "absolute"),
                "destination": os.path.join(c.installdir, "absolute"),
                "expected_contents": "foo",
            },
            # Links with a relative path that points outside of the snap
            # should also be followed
            {
                "source": "../../../../unsnapped",
                "link_name": os.path.join(c.builddir, "foo", "bad_relative"),
                "destination": os.path.join(c.installdir, "bad_relative"),
                "expected_contents": "bar",
            },
        ]

        for symlink in symlinks:
            os.symlink(symlink["source"], symlink["link_name"])

        c.build()

        with open(os.path.join(c.installdir, "file"), "r") as f:
            self.assertThat(f.read(), Equals("foo"))

        for symlink in symlinks:
            destination = symlink["destination"]
            self.assertFalse(
                os.path.islink(destination),
                "Expected {!r} to be a copy rather than a "
                "symlink".format(destination),
            )

            with open(destination, "r") as f:
                self.assertThat(f.read(), Equals(symlink["expected_contents"]))
Ejemplo n.º 23
0
    def test_copy_plugin_any_missing_src_raises_exception(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {
            "src": "dst",
            "zzz": "zzz",
        }
        open("zzz", "w").close()
        c = CopyPlugin("copy", self.mock_options)

        with self.assertRaises(EnvironmentError) as raised:
            c.build()

        self.assertEqual(raised.exception.__str__(), 'file "src" missing')
Ejemplo n.º 24
0
    def test_copy_plugin_handles_dot(self):
        self.mock_options.files = {
            'src': '.',
        }

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        open(os.path.join(c.builddir, 'src'), 'w').close()

        c.build()
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, 'src')))
Ejemplo n.º 25
0
    def test_copy_plugin_handles_leading_slash(self):
        self.mock_options.files = {
            'src': '/dst',
        }
        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        open(os.path.join(c.builddir, 'src'), 'w').close()

        c.build()

        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, 'dst')))
Ejemplo n.º 26
0
    def test_copy_symlinks_that_should_be_followed(self):
        self.mock_options.files = {'foo/*': '.'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, 'foo', 'bar'))
        with open(os.path.join(c.builddir, 'foo', 'file'), 'w') as f:
            f.write('foo')

        with open('unsnapped', 'w') as f:
            f.write('bar')

        symlinks = [
            # Links with an absolute path should be followed
            {
                'source': os.path.join(c.builddir, 'foo', 'file'),
                'link_name': os.path.join(c.builddir, 'foo', 'absolute'),
                'destination': os.path.join(c.installdir, 'absolute'),
                'expected_contents': 'foo',
            },
            # Links with a relative path that points outside of the snap
            # should also be followed
            {
                'source': '../../../../unsnapped',
                'link_name': os.path.join(c.builddir, 'foo', 'bad_relative'),
                'destination': os.path.join(c.installdir, 'bad_relative'),
                'expected_contents': 'bar',
            },
        ]

        for symlink in symlinks:
            os.symlink(symlink['source'], symlink['link_name'])

        c.build()

        with open(os.path.join(c.installdir, 'file'), 'r') as f:
            self.assertEqual(f.read(), 'foo')

        for symlink in symlinks:
            destination = symlink['destination']
            self.assertFalse(os.path.islink(destination),
                             'Expected {!r} to be a copy rather than a '
                             'symlink'.format(destination))

            with open(destination, 'r') as f:
                self.assertEqual(f.read(), symlink['expected_contents'])
Ejemplo n.º 27
0
    def test_copy_plugin_any_missing_src_raises_exception(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {
            'src': 'dst',
            'zzz': 'zzz',
        }
        open('zzz', 'w').close()
        c = CopyPlugin('copy', self.mock_options)

        with self.assertRaises(EnvironmentError) as raised:
            c.build()

        self.assertEqual(raised.exception.__str__(),
                         'file "src" missing')
Ejemplo n.º 28
0
    def test_copy_plugin_any_missing_src_raises_exception(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {
            'src': 'dst',
            'zzz': 'zzz',
        }
        open('zzz', 'w').close()
        c = CopyPlugin('copy', self.mock_options)

        with self.assertRaises(EnvironmentError) as raised:
            c.build()

        self.assertEqual(raised.exception.__str__(),
                         "[Errno 2] No such file or directory: 'src'")
Ejemplo n.º 29
0
    def test_copy_plugin_any_missing_src_raises_exception(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {
            'src': 'dst',
            'zzz': 'zzz',
        }
        open('zzz', 'w').close()
        c = CopyPlugin('copy', self.mock_options, self.project_options)
        c.pull()

        raised = self.assertRaises(EnvironmentError, c.build)

        self.assertEqual(
            str(raised),
            "[Errno 2] No such file or directory: '{}/src'".format(c.builddir))
Ejemplo n.º 30
0
    def test_copy_with_source_and_glob(self):
        self.mock_options.source = 'src'
        self.mock_options.files = {'foo/*': 'baz/'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)
        os.makedirs(os.path.join('src', 'foo'))
        open(os.path.join('src', 'foo', 'bar'), 'w').close()

        c.pull()
        self.assertTrue(
            os.path.isfile(os.path.join(c.sourcedir, 'foo', 'bar')))

        c.build()
        self.assertTrue(os.path.isfile(os.path.join(c.builddir, 'foo', 'bar')))
        self.assertTrue(
            os.path.isfile(os.path.join(c.installdir, 'baz', 'bar')))
Ejemplo n.º 31
0
    def test_copy_plugin_glob(self):
        self.mock_options.files = {"*.txt": "."}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        for filename in ("file-a.txt", "file-b.txt", "file-c.notxt"):
            with open(os.path.join(c.builddir, filename), "w") as datafile:
                datafile.write(filename)

        c.build()

        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, "file-a.txt")))
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, "file-b.txt")))
        self.assertFalse(os.path.exists(os.path.join(self.dst_prefix, "file-c.notxt")))
Ejemplo n.º 32
0
    def test_copy_plugin_any_missing_src_raises_exception(self):
        # ensure that a bad file causes a warning and fails the build even
        # if there is a good file last
        self.mock_options.files = {
            'src': 'dst',
            'zzz': 'zzz',
        }
        open('zzz', 'w').close()
        c = CopyPlugin('copy', self.mock_options, self.project_options)
        c.pull()

        raised = self.assertRaises(EnvironmentError, c.build)

        self.assertEqual(
            str(raised),
            "[Errno 2] No such file or directory: '{}/src'".format(
                c.builddir))
Ejemplo n.º 33
0
    def test_copy_directories(self):
        self.mock_options.files = {"dirs1": "dir/dst"}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.mkdir(os.path.join(c.builddir, "dirs1"))
        open(os.path.join(c.builddir, "dirs1", "f"), "w").close()
        os.makedirs(os.path.join(c.builddir, "foo", "bar"))

        c.pull()
        c.build()
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, "dir", "dst", "f"))
        )
Ejemplo n.º 34
0
    def test_copy_plugin_glob_with_folders(self):
        self.mock_options.files = {
            'foo/*': '.',
        }

        os.makedirs(os.path.join('foo', 'directory'))
        open(os.path.join('foo', 'file1'), 'w').close()
        open(os.path.join('foo', 'directory', 'file2'), 'w').close()

        c = CopyPlugin('copy', self.mock_options, self.project_options)
        c.pull()
        c.build()

        self.assertTrue(os.path.isfile(os.path.join(c.installdir, 'file1')))
        self.assertTrue(os.path.isdir(os.path.join(c.installdir, 'directory')))
        self.assertTrue(os.path.isfile(
            os.path.join(c.installdir, 'directory', 'file2')))
Ejemplo n.º 35
0
    def test_copy_directories(self):
        self.mock_options.files = {
            'dirs1': 'dir/dst',
        }

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.mkdir(os.path.join(c.builddir, 'dirs1'))
        open(os.path.join(c.builddir, 'dirs1', 'f'), 'w').close()
        os.makedirs(os.path.join(c.builddir, 'foo', 'bar'))

        c.pull()
        c.build()
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, 'dir', 'dst', 'f')))
Ejemplo n.º 36
0
    def test_copy_with_source_doesnt_use_cwd(self):
        self.mock_options.source = 'src'
        self.mock_options.files = {'foo/bar': 'baz/qux'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)
        os.mkdir('src')
        os.mkdir('foo')
        open(os.path.join('foo', 'bar'), 'w').close()

        c.pull()

        with self.assertRaises(EnvironmentError) as raised:
            c.build()

        self.assertEqual(
            str(raised.exception),
            "[Errno 2] No such file or directory: '{}/foo/bar'".format(
                c.builddir))
Ejemplo n.º 37
0
    def test_get_build_properties(self):
        expected_build_properties = ['files']
        resulting_build_properties = CopyPlugin.get_build_properties()

        self.assertThat(resulting_build_properties,
                        HasLength(len(expected_build_properties)))

        for property in expected_build_properties:
            self.assertIn(property, resulting_build_properties)
Ejemplo n.º 38
0
    def test_get_build_properties(self):
        expected_build_properties = ['files']
        resulting_build_properties = CopyPlugin.get_build_properties()

        self.assertThat(resulting_build_properties,
                        HasLength(len(expected_build_properties)))

        for property in expected_build_properties:
            self.assertIn(property, resulting_build_properties)
Ejemplo n.º 39
0
    def test_copy_plugin_glob(self):
        self.mock_options.files = {
            '*.txt': '.',
        }

        for filename in ('file-a.txt', 'file-b.txt', 'file-c.notxt'):
            with open(filename, 'w') as datafile:
                datafile.write(filename)

        c = CopyPlugin('copy', self.mock_options)
        c.build()

        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, 'file-a.txt')))
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, 'file-b.txt')))
        self.assertFalse(
            os.path.exists(os.path.join(self.dst_prefix, 'file-c.notxt')))
Ejemplo n.º 40
0
    def test_copy_plugin_glob(self):
        self.mock_options.files = {
            '*.txt': '.',
        }

        for filename in ('file-a.txt', 'file-b.txt', 'file-c.notxt'):
            with open(filename, 'w') as datafile:
                datafile.write(filename)

        c = CopyPlugin('copy', self.mock_options)
        c.build()

        self.assertTrue(os.path.exists(
            os.path.join(self.dst_prefix, 'file-a.txt')))
        self.assertTrue(os.path.exists(
            os.path.join(self.dst_prefix, 'file-b.txt')))
        self.assertFalse(os.path.exists(
            os.path.join(self.dst_prefix, 'file-c.notxt')))
Ejemplo n.º 41
0
    def test_copy_plugin_glob_with_folders(self):
        self.mock_options.files = {"foo/*": "."}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, "foo", "directory"))
        open(os.path.join(c.builddir, "foo", "file1"), "w").close()
        open(os.path.join(c.builddir, "foo", "directory", "file2"),
             "w").close()

        c.build()

        self.assertTrue(os.path.isfile(os.path.join(c.installdir, "file1")))
        self.assertTrue(os.path.isdir(os.path.join(c.installdir, "directory")))
        self.assertTrue(
            os.path.isfile(os.path.join(c.installdir, "directory", "file2")))
Ejemplo n.º 42
0
    def test_copy_plugin_glob_with_folders(self):
        self.mock_options.files = {"foo/*": "."}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, "foo", "directory"))
        open(os.path.join(c.builddir, "foo", "file1"), "w").close()
        open(os.path.join(c.builddir, "foo", "directory", "file2"), "w").close()

        c.build()

        self.assertTrue(os.path.isfile(os.path.join(c.installdir, "file1")))
        self.assertTrue(os.path.isdir(os.path.join(c.installdir, "directory")))
        self.assertTrue(
            os.path.isfile(os.path.join(c.installdir, "directory", "file2"))
        )
Ejemplo n.º 43
0
    def test_copy_plugin_glob(self):
        self.mock_options.files = {"*.txt": "."}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        for filename in ("file-a.txt", "file-b.txt", "file-c.notxt"):
            with open(os.path.join(c.builddir, filename), "w") as datafile:
                datafile.write(filename)

        c.build()

        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, "file-a.txt")))
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, "file-b.txt")))
        self.assertFalse(
            os.path.exists(os.path.join(self.dst_prefix, "file-c.notxt")))
Ejemplo n.º 44
0
    def test_copy_symlinks_to_libc(self):
        self.mock_options.files = {'*': '.'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        # Even though this symlink is absolute, since it's to libc the copy
        # plugin shouldn't try to follow it or modify it.
        libc_libs = snapcraft.repo.get_pkg_libs('libc6')

        # We don't care which lib we're testing with, as long as it's a .so.
        libc_library_path = [lib for lib in libc_libs if '.so' in lib][0]
        os.symlink(libc_library_path, os.path.join(c.builddir, 'libc-link'))

        c.build()

        self.assertThat(os.path.join(c.installdir, 'libc-link'),
                        tests.LinkExists(libc_library_path))
Ejemplo n.º 45
0
    def test_copy_plugin_glob_with_folders(self):
        self.mock_options.files = {
            'foo/*': '.',
        }

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, 'foo', 'directory'))
        open(os.path.join(c.builddir, 'foo', 'file1'), 'w').close()
        open(os.path.join(
            c.builddir, 'foo', 'directory', 'file2'), 'w').close()

        c.build()

        self.assertTrue(os.path.isfile(os.path.join(c.installdir, 'file1')))
        self.assertTrue(os.path.isdir(os.path.join(c.installdir, 'directory')))
        self.assertTrue(os.path.isfile(
            os.path.join(c.installdir, 'directory', 'file2')))
Ejemplo n.º 46
0
    def test_copy_symlinks_to_libc(self):
        self.mock_options.files = {'*': '.'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        # Even though this symlink is absolute, since it's to libc the copy
        # plugin shouldn't try to follow it or modify it.
        libc_libs = snapcraft.repo.Repo.get_package_libraries('libc6')

        # We don't care which lib we're testing with, as long as it's a .so.
        libc_library_path = [lib for lib in libc_libs if '.so' in lib][0]
        os.symlink(libc_library_path, os.path.join(c.builddir, 'libc-link'))

        c.build()

        self.assertThat(
            os.path.join(c.installdir, 'libc-link'),
            tests.LinkExists(libc_library_path))
Ejemplo n.º 47
0
    def test_copy_plugin_glob_with_folders(self):
        self.mock_options.files = {
            'foo/*': '.',
        }

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, 'foo', 'directory'))
        open(os.path.join(c.builddir, 'foo', 'file1'), 'w').close()
        open(os.path.join(c.builddir, 'foo', 'directory', 'file2'),
             'w').close()

        c.build()

        self.assertTrue(os.path.isfile(os.path.join(c.installdir, 'file1')))
        self.assertTrue(os.path.isdir(os.path.join(c.installdir, 'directory')))
        self.assertTrue(
            os.path.isfile(os.path.join(c.installdir, 'directory', 'file2')))
Ejemplo n.º 48
0
    def test_copy_plugin_handles_leading_slash(self):
        self.mock_options.files = {
            'src': '/dst',
        }
        open('src', 'w').close()

        c = CopyPlugin('copy', self.mock_options, self.project_options)
        c.pull()
        c.build()
        self.assertTrue(os.path.exists(os.path.join(self.dst_prefix, 'dst')))
Ejemplo n.º 49
0
    def test_copy_with_source_and_glob(self):
        self.mock_options.source = 'src'
        self.mock_options.files = {'foo/*': 'baz/'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)
        os.makedirs(os.path.join('src', 'foo'))
        open(os.path.join('src', 'foo', 'bar'), 'w').close()

        c.pull()
        self.assertTrue(
            os.path.isfile(os.path.join(c.sourcedir, 'foo', 'bar')))

        c.build()
        self.assertTrue(os.path.isfile(os.path.join(c.builddir, 'foo', 'bar')))
        self.assertTrue(
            os.path.isfile(os.path.join(c.installdir, 'baz', 'bar')))
Ejemplo n.º 50
0
    def test_copy_directories(self):
        self.mock_options.files = {"dirs1": "dir/dst"}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.mkdir(os.path.join(c.builddir, "dirs1"))
        open(os.path.join(c.builddir, "dirs1", "f"), "w").close()
        os.makedirs(os.path.join(c.builddir, "foo", "bar"))

        c.pull()
        c.build()
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, "dir", "dst", "f")))
Ejemplo n.º 51
0
    def test_copy_plugin_glob_with_folders(self):
        self.mock_options.files = {
            'foo/*': '.',
        }

        os.makedirs(os.path.join('foo', 'directory'))
        open(os.path.join('foo', 'file1'), 'w').close()
        open(os.path.join('foo', 'directory', 'file2'), 'w').close()

        c = CopyPlugin('copy', self.mock_options, self.project_options)
        c.pull()
        c.build()

        self.assertTrue(os.path.isfile(os.path.join(c.installdir, 'file1')))
        self.assertTrue(os.path.isdir(os.path.join(c.installdir, 'directory')))
        self.assertTrue(os.path.isfile(
            os.path.join(c.installdir, 'directory', 'file2')))
Ejemplo n.º 52
0
    def test_copy_with_source_doesnt_use_cwd(self):
        self.mock_options.source = 'src'
        self.mock_options.files = {'foo/bar': 'baz/qux'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)
        os.mkdir('src')
        os.mkdir('foo')
        open(os.path.join('foo', 'bar'), 'w').close()

        c.pull()

        with self.assertRaises(EnvironmentError) as raised:
            c.build()

        self.assertEqual(
            str(raised.exception),
            "[Errno 2] No such file or directory: '{}/foo/bar'".format(
                c.builddir))
Ejemplo n.º 53
0
    def test_copy_directories(self):
        self.mock_options.files = {
            'dirs1': 'dir/dst',
        }

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.mkdir(os.path.join(c.builddir, 'dirs1'))
        open(os.path.join(c.builddir, 'dirs1', 'f'), 'w').close()
        os.makedirs(os.path.join(c.builddir, 'foo', 'bar'))

        c.pull()
        c.build()
        self.assertTrue(
            os.path.exists(os.path.join(self.dst_prefix, 'dir', 'dst', 'f')))
Ejemplo n.º 54
0
 def test_copy_enable_cross_compilation(self):
     c = CopyPlugin('copy', self.mock_options, self.project_options)
     c.enable_cross_compilation()
Ejemplo n.º 55
0
 def test_copy_enable_cross_compilation(self):
     c = CopyPlugin('copy', self.mock_options, self.project_options)
     c.enable_cross_compilation()
Ejemplo n.º 56
0
    def test_copy_symlinks(self):
        self.mock_options.files = {'foo/*': 'baz/'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, 'foo', 'bar'))
        with open(os.path.join(c.builddir, 'foo', 'file'), 'w') as f:
            f.write('foo')

        destination = os.path.join(c.installdir, 'baz')

        symlinks = [
            {
                'source': 'file',
                'link_name': os.path.join(c.builddir, 'foo', 'relative1'),
                'destination': os.path.join(destination, 'relative1'),
                'expected_realpath': os.path.join(destination, 'file'),
                'expected_contents': 'foo',
            },
            {
                'source': '../file',
                'link_name': os.path.join(c.builddir, 'foo', 'bar',
                                          'relative2'),
                'destination': os.path.join(destination, 'bar', 'relative2'),
                'expected_realpath': os.path.join(destination, 'file'),
                'expected_contents': 'foo',
            },
            {
                'source': '../../baz/file',
                'link_name': os.path.join(c.builddir, 'foo', 'bar',
                                          'relative3'),
                'destination': os.path.join(destination, 'bar', 'relative3'),
                'expected_realpath': os.path.join(destination, 'file'),
                'expected_contents': 'foo',
            },
        ]

        for symlink in symlinks:
            os.symlink(symlink['source'], symlink['link_name'])

        c.build()

        self.assertTrue(os.path.isdir(destination),
                        "Expected foo's contents to be copied into baz/")
        with open(os.path.join(destination, 'file'), 'r') as f:
            self.assertEqual(f.read(), 'foo')

        for symlink in symlinks:
            destination = symlink['destination']
            self.assertTrue(
                os.path.islink(destination),
                'Expected {!r} to be a symlink'.format(destination))

            self.assertEqual(
                os.path.realpath(destination), symlink['expected_realpath'],
                'Expected {!r} to be a relative path to {!r}'.format(
                    destination, symlink['expected_realpath']))

            with open(destination, 'r') as f:
                self.assertEqual(f.read(), symlink['expected_contents'])
Ejemplo n.º 57
0
    def test_copy_symlinks(self):
        self.mock_options.files = {"foo/*": "baz/"}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, "foo", "bar"))
        with open(os.path.join(c.builddir, "foo", "file"), "w") as f:
            f.write("foo")

        destination = os.path.join(c.installdir, "baz")

        symlinks = [
            {
                "source": "file",
                "link_name": os.path.join(c.builddir, "foo", "relative1"),
                "destination": os.path.join(destination, "relative1"),
                "expected_realpath": os.path.join(destination, "file"),
                "expected_contents": "foo",
            },
            {
                "source": "../file",
                "link_name": os.path.join(c.builddir, "foo", "bar",
                                          "relative2"),
                "destination": os.path.join(destination, "bar", "relative2"),
                "expected_realpath": os.path.join(destination, "file"),
                "expected_contents": "foo",
            },
            {
                "source": "../../baz/file",
                "link_name": os.path.join(c.builddir, "foo", "bar",
                                          "relative3"),
                "destination": os.path.join(destination, "bar", "relative3"),
                "expected_realpath": os.path.join(destination, "file"),
                "expected_contents": "foo",
            },
        ]

        for symlink in symlinks:
            os.symlink(symlink["source"], symlink["link_name"])

        c.build()

        self.assertTrue(os.path.isdir(destination),
                        "Expected foo's contents to be copied into baz/")
        with open(os.path.join(destination, "file"), "r") as f:
            self.assertThat(f.read(), Equals("foo"))

        for symlink in symlinks:
            destination = symlink["destination"]
            self.assertTrue(
                os.path.islink(destination),
                "Expected {!r} to be a symlink".format(destination),
            )

            self.assertThat(
                os.path.realpath(destination),
                Equals(symlink["expected_realpath"]),
                "Expected {!r} to be a relative path to {!r}".format(
                    destination, symlink["expected_realpath"]),
            )

            with open(destination, "r") as f:
                self.assertThat(f.read(), Equals(symlink["expected_contents"]))
Ejemplo n.º 58
0
    def test_copy_symlinks(self):
        self.mock_options.files = {'foo/*': 'baz/'}

        c = CopyPlugin('copy', self.mock_options, self.project_options)

        os.makedirs('foo/bar')
        with open('foo/file', 'w') as f:
            f.write('foo')

        destination = os.path.join(c.installdir, 'baz')

        symlinks = [
            {
                'source': 'file',
                'link_name': 'foo/relative1',
                'destination': os.path.join(destination, 'relative1'),
                'expected_realpath': os.path.join(destination, 'file'),
                'expected_contents': 'foo',
            },
            {
                'source': '../file',
                'link_name': 'foo/bar/relative2',
                'destination': os.path.join(destination, 'bar', 'relative2'),
                'expected_realpath': os.path.join(destination, 'file'),
                'expected_contents': 'foo',
            },
            {
                'source': '../../baz/file',
                'link_name': 'foo/bar/relative3',
                'destination': os.path.join(destination, 'bar', 'relative3'),
                'expected_realpath': os.path.join(destination, 'file'),
                'expected_contents': 'foo',
            },
        ]

        for symlink in symlinks:
            os.symlink(symlink['source'], symlink['link_name'])

        c.pull()
        c.build()

        self.assertTrue(os.path.isdir(destination),
                        "Expected foo's contents to be copied into baz/")
        with open(os.path.join(destination, 'file'), 'r') as f:
            self.assertEqual(f.read(), 'foo')

        for symlink in symlinks:
            destination = symlink['destination']
            with self.subTest('link: {}'.format(destination)):
                self.assertTrue(
                    os.path.islink(destination),
                    'Expected {!r} to be a symlink'.format(destination))

                self.assertEqual(
                    os.path.realpath(destination),
                    symlink['expected_realpath'],
                    'Expected {!r} to be a relative path to {!r}'.format(
                        destination, symlink['expected_realpath']))

                with open(destination, 'r') as f:
                    self.assertEqual(f.read(), symlink['expected_contents'])
Ejemplo n.º 59
0
    def test_copy_symlinks(self):
        self.mock_options.files = {"foo/*": "baz/"}

        c = CopyPlugin("copy", self.mock_options, self.project_options)

        # These directories are created by the pluginhandler
        os.makedirs(c.builddir)

        os.makedirs(os.path.join(c.builddir, "foo", "bar"))
        with open(os.path.join(c.builddir, "foo", "file"), "w") as f:
            f.write("foo")

        destination = os.path.join(c.installdir, "baz")

        symlinks = [
            {
                "source": "file",
                "link_name": os.path.join(c.builddir, "foo", "relative1"),
                "destination": os.path.join(destination, "relative1"),
                "expected_realpath": os.path.join(destination, "file"),
                "expected_contents": "foo",
            },
            {
                "source": "../file",
                "link_name": os.path.join(c.builddir, "foo", "bar", "relative2"),
                "destination": os.path.join(destination, "bar", "relative2"),
                "expected_realpath": os.path.join(destination, "file"),
                "expected_contents": "foo",
            },
            {
                "source": "../../baz/file",
                "link_name": os.path.join(c.builddir, "foo", "bar", "relative3"),
                "destination": os.path.join(destination, "bar", "relative3"),
                "expected_realpath": os.path.join(destination, "file"),
                "expected_contents": "foo",
            },
        ]

        for symlink in symlinks:
            os.symlink(symlink["source"], symlink["link_name"])

        c.build()

        self.assertTrue(
            os.path.isdir(destination), "Expected foo's contents to be copied into baz/"
        )
        with open(os.path.join(destination, "file"), "r") as f:
            self.assertThat(f.read(), Equals("foo"))

        for symlink in symlinks:
            destination = symlink["destination"]
            self.assertTrue(
                os.path.islink(destination),
                "Expected {!r} to be a symlink".format(destination),
            )

            self.assertThat(
                os.path.realpath(destination),
                Equals(symlink["expected_realpath"]),
                "Expected {!r} to be a relative path to {!r}".format(
                    destination, symlink["expected_realpath"]
                ),
            )

            with open(destination, "r") as f:
                self.assertThat(f.read(), Equals(symlink["expected_contents"]))