Aluode/PerceptionLabPortable
0
1"""Tests for distutils.command.install_data."""2 3import os4import pathlib5from distutils.command.install_data import install_data6from distutils.tests import support7 8import pytest9 10 11@pytest.mark.usefixtures('save_env')12class TestInstallData(13 support.TempdirManager,14):15 def test_simple_run(self):16 pkg_dir, dist = self.create_dist()17 cmd = install_data(dist)18 cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')19 20 # data_files can contain21 # - simple files22 # - a Path object23 # - a tuple with a path, and a list of file24 one = os.path.join(pkg_dir, 'one')25 self.write_file(one, 'xxx')26 inst2 = os.path.join(pkg_dir, 'inst2')27 two = os.path.join(pkg_dir, 'two')28 self.write_file(two, 'xxx')29 three = pathlib.Path(pkg_dir) / 'three'30 self.write_file(three, 'xxx')31 32 cmd.data_files = [one, (inst2, [two]), three]33 assert cmd.get_inputs() == [one, (inst2, [two]), three]34 35 # let's run the command36 cmd.ensure_finalized()37 cmd.run()38 39 # let's check the result40 assert len(cmd.get_outputs()) == 341 rthree = os.path.split(one)[-1]42 assert os.path.exists(os.path.join(inst, rthree))43 rtwo = os.path.split(two)[-1]44 assert os.path.exists(os.path.join(inst2, rtwo))45 rone = os.path.split(one)[-1]46 assert os.path.exists(os.path.join(inst, rone))47 cmd.outfiles = []48 49 # let's try with warn_dir one50 cmd.warn_dir = True51 cmd.ensure_finalized()52 cmd.run()53 54 # let's check the result55 assert len(cmd.get_outputs()) == 356 assert os.path.exists(os.path.join(inst, rthree))57 assert os.path.exists(os.path.join(inst2, rtwo))58 assert os.path.exists(os.path.join(inst, rone))59 cmd.outfiles = []60 61 # now using root and empty dir62 cmd.root = os.path.join(pkg_dir, 'root')63 inst5 = os.path.join(pkg_dir, 'inst5')64 four = os.path.join(cmd.install_dir, 'four')65 self.write_file(four, 'xx')66 cmd.data_files = [one, (inst2, [two]), three, ('inst5', [four]), (inst5, [])]67 cmd.ensure_finalized()68 cmd.run()69 70 # let's check the result71 assert len(cmd.get_outputs()) == 572 assert os.path.exists(os.path.join(inst, rthree))73 assert os.path.exists(os.path.join(inst2, rtwo))74 assert os.path.exists(os.path.join(inst, rone))75 