|
18 | 18 | get_python_env_info,
|
19 | 19 | inspect_environment,
|
20 | 20 | list_files,
|
| 21 | + make_html_bundle, |
21 | 22 | make_manifest_bundle,
|
22 | 23 | make_notebook_html_bundle,
|
23 | 24 | make_notebook_source_bundle,
|
@@ -1512,3 +1513,205 @@ def test_create_html_manifest():
|
1512 | 1513 | extra_files=[multi_file_index_file2],
|
1513 | 1514 | )
|
1514 | 1515 | assert multi_file_index_dir_extras_ans == json.loads(manifest.flattened_copy.json)
|
| 1516 | + |
| 1517 | + |
| 1518 | +def test_make_html_bundle(): |
| 1519 | + single_file_index_file_ans = { |
| 1520 | + "version": 1, |
| 1521 | + "metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"}, |
| 1522 | + "files": {"index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}}, |
| 1523 | + } |
| 1524 | + with make_html_bundle( |
| 1525 | + single_file_index_file, |
| 1526 | + None, |
| 1527 | + None, |
| 1528 | + None, |
| 1529 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1530 | + names = sorted(tar.getnames()) |
| 1531 | + assert names == [ |
| 1532 | + "index.html", |
| 1533 | + "manifest.json", |
| 1534 | + ] |
| 1535 | + assert single_file_index_file_ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) |
| 1536 | + |
| 1537 | + single_file_index_dir_ans = { |
| 1538 | + "version": 1, |
| 1539 | + "metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"}, |
| 1540 | + "files": { |
| 1541 | + "index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1542 | + "test1.txt": {"checksum": "3e7705498e8be60520841409ebc69bc1"}, |
| 1543 | + "test_folder1/testfoldertext1.txt": {"checksum": "0a576fd324b6985bac6aa934131d2f5c"}, |
| 1544 | + }, |
| 1545 | + } |
| 1546 | + with make_html_bundle( |
| 1547 | + single_file_index_dir, |
| 1548 | + None, |
| 1549 | + None, |
| 1550 | + None, |
| 1551 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1552 | + names = sorted(tar.getnames()) |
| 1553 | + assert names == [ |
| 1554 | + "index.html", |
| 1555 | + "manifest.json", |
| 1556 | + "test1.txt", |
| 1557 | + "test_folder1/testfoldertext1.txt", |
| 1558 | + ] |
| 1559 | + assert single_file_index_dir_ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) |
| 1560 | + |
| 1561 | + with make_html_bundle( |
| 1562 | + single_file_index_dir, |
| 1563 | + single_file_index_file, |
| 1564 | + None, |
| 1565 | + None, |
| 1566 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1567 | + names = sorted(tar.getnames()) |
| 1568 | + assert names == [ |
| 1569 | + "index.html", |
| 1570 | + "manifest.json", |
| 1571 | + "test1.txt", |
| 1572 | + "test_folder1/testfoldertext1.txt", |
| 1573 | + ] |
| 1574 | + assert single_file_index_dir_ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) |
| 1575 | + |
| 1576 | + multi_file_index_file_ans = { |
| 1577 | + "version": 1, |
| 1578 | + "metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"}, |
| 1579 | + "files": {"index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}}, |
| 1580 | + } |
| 1581 | + with make_html_bundle( |
| 1582 | + multi_file_index_file, |
| 1583 | + None, |
| 1584 | + None, |
| 1585 | + None, |
| 1586 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1587 | + names = sorted(tar.getnames()) |
| 1588 | + assert names == [ |
| 1589 | + "index.html", |
| 1590 | + "manifest.json", |
| 1591 | + ] |
| 1592 | + assert multi_file_index_file_ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) |
| 1593 | + |
| 1594 | + multi_file_index_dir_ans = { |
| 1595 | + "version": 1, |
| 1596 | + "metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"}, |
| 1597 | + "files": { |
| 1598 | + "index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1599 | + "main.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1600 | + }, |
| 1601 | + } |
| 1602 | + with make_html_bundle( |
| 1603 | + multi_file_index_dir, |
| 1604 | + None, |
| 1605 | + None, |
| 1606 | + None, |
| 1607 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1608 | + names = sorted(tar.getnames()) |
| 1609 | + assert names == [ |
| 1610 | + "index.html", |
| 1611 | + "main.html", |
| 1612 | + "manifest.json", |
| 1613 | + ] |
| 1614 | + assert multi_file_index_dir_ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) |
| 1615 | + |
| 1616 | + with make_html_bundle( |
| 1617 | + multi_file_index_dir, |
| 1618 | + multi_file_index_file, |
| 1619 | + None, |
| 1620 | + None, |
| 1621 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1622 | + names = sorted(tar.getnames()) |
| 1623 | + assert names == [ |
| 1624 | + "index.html", |
| 1625 | + "main.html", |
| 1626 | + "manifest.json", |
| 1627 | + ] |
| 1628 | + assert multi_file_index_dir_ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) |
| 1629 | + |
| 1630 | + multi_file_nonindex_file_ans = { |
| 1631 | + "version": 1, |
| 1632 | + "metadata": {"appmode": "static", "primary_html": "b.html", "entrypoint": "b.html"}, |
| 1633 | + "files": {"b.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}}, |
| 1634 | + } |
| 1635 | + with make_html_bundle( |
| 1636 | + multi_file_nonindex_fileb, |
| 1637 | + None, |
| 1638 | + None, |
| 1639 | + None, |
| 1640 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1641 | + names = sorted(tar.getnames()) |
| 1642 | + assert names == [ |
| 1643 | + "b.html", |
| 1644 | + "manifest.json", |
| 1645 | + ] |
| 1646 | + assert multi_file_nonindex_file_ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) |
| 1647 | + |
| 1648 | + multi_file_nonindex_dir_and_file_ans = { |
| 1649 | + "version": 1, |
| 1650 | + "metadata": {"appmode": "static", "primary_html": "b.html", "entrypoint": "b.html"}, |
| 1651 | + "files": { |
| 1652 | + "a.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1653 | + "b.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1654 | + }, |
| 1655 | + } |
| 1656 | + with make_html_bundle( |
| 1657 | + multi_file_nonindex_dir, |
| 1658 | + multi_file_nonindex_fileb, |
| 1659 | + None, |
| 1660 | + None, |
| 1661 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1662 | + names = sorted(tar.getnames()) |
| 1663 | + assert names == [ |
| 1664 | + "a.html", |
| 1665 | + "b.html", |
| 1666 | + "manifest.json", |
| 1667 | + ] |
| 1668 | + assert multi_file_nonindex_dir_and_file_ans == json.loads( |
| 1669 | + tar.extractfile("manifest.json").read().decode("utf-8") |
| 1670 | + ) |
| 1671 | + |
| 1672 | + multi_file_nonindex_file_extras_ans = { |
| 1673 | + "version": 1, |
| 1674 | + "metadata": {"appmode": "static", "primary_html": "b.html", "entrypoint": "b.html"}, |
| 1675 | + "files": { |
| 1676 | + "a.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1677 | + "b.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1678 | + }, |
| 1679 | + } |
| 1680 | + with make_html_bundle( |
| 1681 | + multi_file_nonindex_fileb, |
| 1682 | + None, |
| 1683 | + [multi_file_nonindex_filea], |
| 1684 | + None, |
| 1685 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1686 | + names = sorted(tar.getnames()) |
| 1687 | + assert names == [ |
| 1688 | + "a.html", |
| 1689 | + "b.html", |
| 1690 | + "manifest.json", |
| 1691 | + ] |
| 1692 | + assert multi_file_nonindex_file_extras_ans == json.loads( |
| 1693 | + tar.extractfile("manifest.json").read().decode("utf-8") |
| 1694 | + ) |
| 1695 | + |
| 1696 | + multi_file_index_dir_extras_ans = { |
| 1697 | + "version": 1, |
| 1698 | + "metadata": {"appmode": "static", "primary_html": "index.html", "entrypoint": "index.html"}, |
| 1699 | + "files": { |
| 1700 | + "index.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1701 | + "main.html": {"checksum": "c14bd63e50295f94b761ffe9d41e3742"}, |
| 1702 | + }, |
| 1703 | + } |
| 1704 | + |
| 1705 | + with make_html_bundle( |
| 1706 | + multi_file_index_dir, |
| 1707 | + None, |
| 1708 | + [multi_file_index_file2], |
| 1709 | + None, |
| 1710 | + ) as bundle, tarfile.open(mode="r:gz", fileobj=bundle) as tar: |
| 1711 | + names = sorted(tar.getnames()) |
| 1712 | + assert names == [ |
| 1713 | + "index.html", |
| 1714 | + "main.html", |
| 1715 | + "manifest.json", |
| 1716 | + ] |
| 1717 | + assert multi_file_index_dir_extras_ans == json.loads(tar.extractfile("manifest.json").read().decode("utf-8")) |
0 commit comments