Example #1
0
def test_edit_name(create_torrent, tmp_path, assert_torrents_equal):
    outfile = str(tmp_path / 'out.torrent')
    with create_torrent() as infile:
        orig = torf.Torrent.read(infile)
        run(['-i', infile, '--name', 'new name', '-o', outfile])
        new = torf.Torrent.read(outfile)
        assert_torrents_equal(orig, new, ignore=('name', 'files', 'filetree'))

        assert new.name == 'new name'
        for of,nf in zip(orig.files, new.files):
            assert nf.parts[0] == 'new name'
            assert nf.parts[1:] == of.parts[1:]

        assert new.filetree == {'new name': {'Anotherthing.iso': torf.File('new name/Anotherthing.iso', size=9),
                                             'Something.jpg': torf.File('new name/Something.jpg', size=9),
                                             'Thirdthing.txt': torf.File('new name/Thirdthing.txt', size=9)}}
Example #2
0
def test_edit_path(create_torrent, tmp_path, assert_torrents_equal):
    outfile = str(tmp_path / 'out.torrent')
    new_content = tmp_path / 'new content'
    new_content.mkdir()
    new_file = new_content / 'some file'
    new_file.write_text('different data')
    with create_torrent() as infile:
        orig = torf.Torrent.read(infile)
        run(['-i', infile, str(new_content), '-o', outfile])
        new = torf.Torrent.read(outfile)
        assert_torrents_equal(orig, new, ignore=('files', 'filetree', 'name',
                                                 'piece_size', 'pieces', 'size'))
        assert tuple(new.files) == (torf.File('new content/some file', size=14),)
        assert new.filetree == {'new content': {'some file': torf.File('new content/some file', size=14)}}
        assert new.name == 'new content'
        assert new.size == len('different data')
Example #3
0
def test_edit_path_with_exclude_regex_option(create_torrent, tmp_path, assert_torrents_equal):
    outfile = str(tmp_path / 'out.torrent')
    new_content = tmp_path / 'new content'
    new_content.mkdir()
    new_file1 = new_content / 'some image.jpg'
    new_file1.write_text('image data')
    new_file2 = new_content / 'some text.txt'
    new_file2.write_text('text data')
    with create_torrent() as infile:
        orig = torf.Torrent.read(infile)
        run(['-i', infile, str(new_content), '--exclude-regex', r'.*\.txt$', '-o', outfile])
        new = torf.Torrent.read(outfile)
        assert_torrents_equal(orig, new, ignore=('files', 'filetree', 'name',
                                                 'piece_size', 'pieces', 'size'))
        assert tuple(new.files) == (torf.File('new content/some image.jpg', size=10),)
        assert new.filetree == {'new content': {'some image.jpg': torf.File('new content/some image.jpg',
                                                                            size=10)}}
        assert new.name == 'new content'
        assert new.size == len('image data')
Example #4
0
def test_include_glob(capsys, tmp_path):
    content = tmp_path / 'My Content'
    content.mkdir()
    new_file1 = content / 'file1.jpg'
    new_file1.write_text('image data')
    new_file2 = content / 'file2.jpg'
    new_file2.write_text('image data')

    exp_torrent_filepath = content.name + '.torrent'
    run([str(content), '--exclude', '*.jpg', '--include', '*file2*'])
    t = torf.Torrent.read(exp_torrent_filepath)
    assert tuple(t.files) == (torf.File('My Content/file2.jpg', size=10), )

    cap = capsys.readouterr()
    assert 'Exclude\t*.jpg' in cap.out
    assert 'Include\t*file2*' in cap.out
    assert 'File Count\t1' in cap.out