Exemplo n.º 1
0
 def test_files(self):
     installer_mock = Mock(spec=installer.Installer)
     installer_mock.path = None
     files1 = fomod.Files()
     file1 = fomod.File("file", attrib={"priority": "2"})
     file1.src = "source1"
     file1.dst = "dest1"
     files1._file_list = [file1]
     installer_mock.root = Mock(spec=fomod.Root)
     installer_mock.root.files = files1
     files2 = fomod.Files()
     file2 = fomod.File("file", attrib={"priority": "0"})
     file2.src = "source2"
     file2.dst = "dest1"
     file3 = fomod.File("file", attrib={"priority": "0"})
     file3.src = "source3"
     file3.dst = "dest2"
     files2._file_list = [file2, file3]
     option2 = fomod.Option()
     option2.files = files2
     installer_mock._previous_pages = OrderedDict([(None, [option2])])
     files3 = fomod.Files()
     file4 = fomod.File("file", attrib={"priority": "1"})
     file4.src = "source4"
     file4.dst = "dest3"
     files3._file_list = [file4]
     installer_mock.root.file_patterns = {fomod.Conditions(): files3}
     expected = {"source1": "dest1", "source3": "dest2", "source4": "dest3"}
     assert installer.Installer.files(installer_mock) == expected
Exemplo n.º 2
0
 def test_getitem(self):
     item1 = fomod.File("file")
     item1.src = "boop"
     item1.dst = "boopity"
     item2 = fomod.File("folder")
     item2.src = "beep"
     item2.dst = "beepity"
     self.files._file_list.extend([item1, item2])
     assert self.files["boop"] == "boopity"
     assert self.files["beep/"] == "beepity"
Exemplo n.º 3
0
 def test_delitem(self):
     item1 = fomod.File("file")
     item1.src = "boop"
     item1.dst = "boopity"
     item2 = fomod.File("folder")
     item2.src = "beep"
     item2.dst = "beepity"
     self.files._file_list.extend([item1, item2])
     assert list(self.files.keys()) == ["boop", "beep/"]
     del self.files["beep/"]
     assert list(self.files.keys()) == ["boop"]
Exemplo n.º 4
0
 def setup_method(self):
     self.file = fomod.File()
Exemplo n.º 5
0
def test_fileinfo_process_files(tmp_path):
    def fileinfo_list_contains(info_list, test_info):
        for fileinfo in info_list:
            if (test_info.source == fileinfo.source
                    and test_info.destination == fileinfo.destination
                    and test_info.priority == fileinfo.priority):
                return True
        return False

    test_files = fomod.Files()
    test_file = fomod.File("file")
    test_file.src = "file1"
    test_file.dst = None
    test_files._file_list.append(test_file)
    test_file = fomod.File("file")
    test_file.src = "file2"
    test_file.dst = ""
    test_files._file_list.append(test_file)
    test_file = fomod.File("file")
    test_file.src = "file3"
    test_file.dst = "dest1/"
    test_files._file_list.append(test_file)
    test_file = fomod.File("file", attrib={"priority": "1"})
    test_file.src = "file4"
    test_file.dst = "dest2"
    test_files._file_list.append(test_file)
    test_file = fomod.File("file")
    test_file.src = "folder1"
    test_file.dst = None
    (tmp_path / "folder1").mkdir()
    (tmp_path / "folder1" / "file11").touch()
    (tmp_path / "folder1" / "folder11").mkdir()
    (tmp_path / "folder1" / "folder12").mkdir()
    (tmp_path / "folder1" / "folder12" / "file12").touch()
    test_files._file_list.append(test_file)
    test_file = fomod.File("file")
    test_file.src = "folder2"
    test_file.dst = ""
    (tmp_path / "folder2").mkdir()
    (tmp_path / "folder2" / "file21").touch()
    (tmp_path / "folder2" / "folder21").mkdir()
    (tmp_path / "folder2" / "folder22").mkdir()
    (tmp_path / "folder2" / "folder22" / "file22").touch()
    test_files._file_list.append(test_file)
    test_file = fomod.File("file")
    test_file.src = "folder3"
    test_file.dst = "dest3/"
    (tmp_path / "folder3").mkdir()
    (tmp_path / "folder3" / "file31").touch()
    (tmp_path / "folder3" / "folder31").mkdir()
    (tmp_path / "folder3" / "folder32").mkdir()
    (tmp_path / "folder3" / "folder32" / "file32").touch()
    test_files._file_list.append(test_file)
    test_file = fomod.File("file", attrib={"priority": "1"})
    test_file.src = "folder4"
    test_file.dst = "dest4"
    (tmp_path / "folder4").mkdir()
    (tmp_path / "folder4" / "file41").touch()
    (tmp_path / "folder4" / "folder41").mkdir()
    (tmp_path / "folder4" / "folder42").mkdir()
    (tmp_path / "folder4" / "folder42" / "file42").touch()
    test_files._file_list.append(test_file)
    test_file = fomod.File("folder")
    test_file.src = "folder6"
    test_file.dst = None
    (tmp_path / "folder6").mkdir()
    (tmp_path / "folder6" / "file61").touch()
    (tmp_path / "folder6" / "folder61").mkdir()
    (tmp_path / "folder6" / "folder62").mkdir()
    (tmp_path / "folder6" / "folder62" / "file62").touch()
    test_files._file_list.append(test_file)
    test_file = fomod.File("folder")
    test_file.src = "folder7"
    test_file.dst = ""
    (tmp_path / "folder7").mkdir()
    (tmp_path / "folder7" / "file71").touch()
    (tmp_path / "folder7" / "folder71").mkdir()
    (tmp_path / "folder7" / "folder72").mkdir()
    (tmp_path / "folder7" / "folder72" / "file72").touch()
    test_files._file_list.append(test_file)
    test_file = fomod.File("folder")
    test_file.src = "folder8"
    test_file.dst = "dest5"
    (tmp_path / "folder8").mkdir()
    (tmp_path / "folder8" / "file81").touch()
    (tmp_path / "folder8" / "folder81").mkdir()
    (tmp_path / "folder8" / "folder82").mkdir()
    (tmp_path / "folder8" / "folder82" / "file82").touch()
    test_files._file_list.append(test_file)
    test_file = fomod.File("folder", attrib={"priority": "1"})
    test_file.src = "folder9"
    test_file.dst = "dest6"
    (tmp_path / "folder9").mkdir()
    (tmp_path / "folder9" / "file91").touch()
    (tmp_path / "folder9" / "folder91").mkdir()
    (tmp_path / "folder9" / "folder92").mkdir()
    (tmp_path / "folder9" / "folder92" / "file92").touch()
    test_files._file_list.append(test_file)
    expected = [
        installer.FileInfo("file1", "file1", 0),
        installer.FileInfo("file2", "file2", 0),
        installer.FileInfo("file3", str(Path("dest1", "file3")), 0),
        installer.FileInfo("file4", "dest2", 1),
        installer.FileInfo("folder1", "folder1", 0),
        installer.FileInfo("folder2", "folder2", 0),
        installer.FileInfo("folder3", str(Path("dest3", "folder3")), 0),
        installer.FileInfo("folder4", "dest4", 1),
        installer.FileInfo("folder6", "folder6", 0),
        installer.FileInfo("folder7", ".", 0),
        installer.FileInfo("folder8", "dest5", 0),
        installer.FileInfo("folder9", "dest6", 1),
    ]
    result = installer.FileInfo.process_files(test_files, None)
    assert len(result) == len(expected)
    for info in result:
        assert fileinfo_list_contains(expected, info)
    expected = [
        installer.FileInfo("file1", "file1", 0),
        installer.FileInfo("file2", "file2", 0),
        installer.FileInfo("file3", str(Path("dest1", "file3")), 0),
        installer.FileInfo("file4", "dest2", 1),
        installer.FileInfo(str(Path("folder1", "file11")),
                           str(Path("folder1", "file11")), 0),
        installer.FileInfo(str(Path("folder1", "folder11")),
                           str(Path("folder1", "folder11")), 0),
        installer.FileInfo(
            str(Path("folder1", "folder12", "file12")),
            str(Path("folder1", "folder12", "file12")),
            0,
        ),
        installer.FileInfo(str(Path("folder2", "file21")),
                           str(Path("folder2", "file21")), 0),
        installer.FileInfo(str(Path("folder2", "folder21")),
                           str(Path("folder2", "folder21")), 0),
        installer.FileInfo(
            str(Path("folder2", "folder22", "file22")),
            str(Path("folder2", "folder22", "file22")),
            0,
        ),
        installer.FileInfo(str(Path("folder3", "file31")),
                           str(Path("dest3", "folder3", "file31")), 0),
        installer.FileInfo(
            str(Path("folder3", "folder31")),
            str(Path("dest3", "folder3", "folder31")),
            0,
        ),
        installer.FileInfo(
            str(Path("folder3", "folder32", "file32")),
            str(Path("dest3", "folder3", "folder32", "file32")),
            0,
        ),
        installer.FileInfo(str(Path("folder4", "file41")),
                           str(Path("dest4", "file41")), 1),
        installer.FileInfo(str(Path("folder4", "folder41")),
                           str(Path("dest4", "folder41")), 1),
        installer.FileInfo(
            str(Path("folder4", "folder42", "file42")),
            str(Path("dest4", "folder42", "file42")),
            1,
        ),
        installer.FileInfo(str(Path("folder6", "file61")),
                           str(Path("folder6", "file61")), 0),
        installer.FileInfo(str(Path("folder6", "folder61")),
                           str(Path("folder6", "folder61")), 0),
        installer.FileInfo(
            str(Path("folder6", "folder62", "file62")),
            str(Path("folder6", "folder62", "file62")),
            0,
        ),
        installer.FileInfo(str(Path("folder7", "file71")), "file71", 0),
        installer.FileInfo(str(Path("folder7", "folder71")), "folder71", 0),
        installer.FileInfo(
            str(Path("folder7", "folder72", "file72")),
            str(Path("folder72", "file72")),
            0,
        ),
        installer.FileInfo(str(Path("folder8", "file81")),
                           str(Path("dest5", "file81")), 0),
        installer.FileInfo(str(Path("folder8", "folder81")),
                           str(Path("dest5", "folder81")), 0),
        installer.FileInfo(
            str(Path("folder8", "folder82", "file82")),
            str(Path("dest5", "folder82", "file82")),
            0,
        ),
        installer.FileInfo(str(Path("folder9", "file91")),
                           str(Path("dest6", "file91")), 1),
        installer.FileInfo(str(Path("folder9", "folder91")),
                           str(Path("dest6", "folder91")), 1),
        installer.FileInfo(
            str(Path("folder9", "folder92", "file92")),
            str(Path("dest6", "folder92", "file92")),
            1,
        ),
    ]
    result = installer.FileInfo.process_files(test_files, tmp_path)
    assert len(result) == len(expected)
    for info in result:
        assert fileinfo_list_contains(expected, info)