|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | from .helpers.global_data import PostgresNodeService
|
2 | 4 | from .helpers.global_data import PostgresNodeServices
|
3 | 5 | from .helpers.global_data import OsOperations
|
|
13 | 15 | from testgres import ProcessType
|
14 | 16 | from testgres import NodeStatus
|
15 | 17 | from testgres import IsolationLevel
|
| 18 | +from testgres import NodeApp |
16 | 19 |
|
17 | 20 | # New name prevents to collect test-functions in TestgresException and fixes
|
18 | 21 | # the problem with pytest warning.
|
@@ -1584,6 +1587,88 @@ def test_node__no_port_manager(self, node_svc: PostgresNodeService):
|
1584 | 1587 | finally:
|
1585 | 1588 | node_svc.port_manager.release_port(port)
|
1586 | 1589 |
|
| 1590 | + class tag_rmdirs_protector: |
| 1591 | + _os_ops: OsOperations |
| 1592 | + _cwd: str |
| 1593 | + _old_rmdirs: any |
| 1594 | + _cwd: str |
| 1595 | + |
| 1596 | + def __init__(self, os_ops: OsOperations): |
| 1597 | + self._os_ops = os_ops |
| 1598 | + self._cwd = os.path.abspath(os_ops.cwd()) |
| 1599 | + self._old_rmdirs = os_ops.rmdirs |
| 1600 | + |
| 1601 | + def __enter__(self): |
| 1602 | + assert self._os_ops.rmdirs == self._old_rmdirs |
| 1603 | + self._os_ops.rmdirs = self.proxy__rmdirs |
| 1604 | + return self |
| 1605 | + |
| 1606 | + def __exit__(self, exc_type, exc_val, exc_tb): |
| 1607 | + assert self._os_ops.rmdirs == self.proxy__rmdirs |
| 1608 | + self._os_ops.rmdirs = self._old_rmdirs |
| 1609 | + return False |
| 1610 | + |
| 1611 | + def proxy__rmdirs(self, path, ignore_errors=True): |
| 1612 | + raise Exception("Call of rmdirs is not expected!") |
| 1613 | + |
| 1614 | + def test_node_app__make_empty__base_dir_is_None(self, node_svc: PostgresNodeService): |
| 1615 | + assert type(node_svc) == PostgresNodeService # noqa: E721 |
| 1616 | + |
| 1617 | + assert isinstance(node_svc.os_ops, OsOperations) |
| 1618 | + assert node_svc.port_manager is not None |
| 1619 | + assert isinstance(node_svc.port_manager, PortManager) |
| 1620 | + |
| 1621 | + tmp_dir = node_svc.os_ops.mkdtemp() |
| 1622 | + assert tmp_dir is not None |
| 1623 | + assert type(tmp_dir) == str # noqa: E721 |
| 1624 | + logging.info("temp directory is [{}]".format(tmp_dir)) |
| 1625 | + |
| 1626 | + # ----------- |
| 1627 | + os_ops = node_svc.os_ops.create_clone() |
| 1628 | + assert os_ops is not node_svc.os_ops |
| 1629 | + |
| 1630 | + # ----------- |
| 1631 | + with __class__.tag_rmdirs_protector(os_ops): |
| 1632 | + node_app = NodeApp(test_path=tmp_dir, os_ops=os_ops) |
| 1633 | + |
| 1634 | + with pytest.raises(expected_exception=ValueError) as x: |
| 1635 | + node_app.make_empty(base_dir=None) |
| 1636 | + |
| 1637 | + assert str(x.value) == "Argument 'base_dir' is not defined." |
| 1638 | + |
| 1639 | + # ----------- |
| 1640 | + logging.info("temp directory [{}] is deleting".format(tmp_dir)) |
| 1641 | + node_svc.os_ops.rmdir(tmp_dir) |
| 1642 | + |
| 1643 | + def test_node_app__make_empty__base_dir_is_Empty(self, node_svc: PostgresNodeService): |
| 1644 | + assert type(node_svc) == PostgresNodeService # noqa: E721 |
| 1645 | + |
| 1646 | + assert isinstance(node_svc.os_ops, OsOperations) |
| 1647 | + assert node_svc.port_manager is not None |
| 1648 | + assert isinstance(node_svc.port_manager, PortManager) |
| 1649 | + |
| 1650 | + tmp_dir = node_svc.os_ops.mkdtemp() |
| 1651 | + assert tmp_dir is not None |
| 1652 | + assert type(tmp_dir) == str # noqa: E721 |
| 1653 | + logging.info("temp directory is [{}]".format(tmp_dir)) |
| 1654 | + |
| 1655 | + # ----------- |
| 1656 | + os_ops = node_svc.os_ops.create_clone() |
| 1657 | + assert os_ops is not node_svc.os_ops |
| 1658 | + |
| 1659 | + # ----------- |
| 1660 | + with __class__.tag_rmdirs_protector(os_ops): |
| 1661 | + node_app = NodeApp(test_path=tmp_dir, os_ops=os_ops) |
| 1662 | + |
| 1663 | + with pytest.raises(expected_exception=ValueError) as x: |
| 1664 | + node_app.make_empty(base_dir="") |
| 1665 | + |
| 1666 | + assert str(x.value) == "Argument 'base_dir' is empty." |
| 1667 | + |
| 1668 | + # ----------- |
| 1669 | + logging.info("temp directory [{}] is deleting".format(tmp_dir)) |
| 1670 | + node_svc.os_ops.rmdir(tmp_dir) |
| 1671 | + |
1587 | 1672 | @staticmethod
|
1588 | 1673 | def helper__get_node(
|
1589 | 1674 | node_svc: PostgresNodeService,
|
|
0 commit comments