Add pkg_dir attribute, clean up code, and update respective tests

This commit is contained in:
Eric Torres 2019-03-18 05:29:35 -07:00
parent d8eb9837af
commit 66ce230f40
2 changed files with 33 additions and 23 deletions

View File

@ -1,7 +1,7 @@
""" """
.. author:: Eric Torres .. author:: Eric Torres
.. module:: rbackup.hierarchy.snapshot .. module:: rbackup.hierarchy.snapshot
:synopsis: Classes for creating the /tmp hierarchy. :synopsis: Classes for creating the backup hierarchy.
""" """
import logging import logging
@ -29,52 +29,56 @@ class Snapshot(Hierarchy):
"""Default constructor for the Snapshot class.""" """Default constructor for the Snapshot class."""
super().__init__(path) super().__init__(path)
self._boot_dir = self.path / "boot"
self._etc_dir = self.path / "etc"
self._home_dir = self.path / "home"
self._root_home_dir = self.path / "root"
@property @property
def boot_dir(self): def boot_dir(self):
"""Retrieve the /boot /tmp directory of this snapshot. """Retrieve the /boot backup directory of this snapshot.
Example Example
------- -------
>>> s = Snapshot('/tmp/data/snapshot-new') >>> s = Snapshot('backup/data/snapshot-new')
>>> s.boot_dir >>> s.boot_dir
PosixPath('/tmp/data/snapshot-new/boot') PosixPath('backup/data/snapshot-new/boot/loader')
:rtype: path-like object :rtype: path-like object
""" """
return self._boot_dir return self.path / "boot" / "loader"
@property @property
def etc_dir(self): def etc_dir(self):
"""Retrieve the /etc /tmp directory of this snapshot. """Retrieve the /etc backup directory of this snapshot.
Example Example
------- -------
>>> s = Snapshot('/tmp/data/snapshot-new') >>> s = Snapshot('backup/data/snapshot-new')
>>> s.etc_dir >>> s.etc_dir
PosixPath('/tmp/data/snapshot-new/etc') PosixPath('backup/data/snapshot-new/etc')
:rtype: path-like object :rtype: path-like object
""" """
return self._etc_dir return self.path / "etc"
@property @property
def home_dir(self): def home_dir(self):
"""Retrieve the /home /tmp directory of this snapshot. """Retrieve the /home backup directory of this snapshot.
Example Example
------- -------
>>> s = Snapshot('/tmp/data/snapshot-new') >>> s = Snapshot('backup/data/snapshot-new')
>>> s.home_dir >>> s.home_dir
PosixPath('/tmp/data/snapshot-new/home') PosixPath('backup/data/snapshot-new/home')
:rtype: path-like object :rtype: path-like object
""" """
return self._home_dir return self.path / "home"
@property
def pkg_dir(self):
"""Retrieve the package manager backup directory of this snapshot.
>>> s = Snapshot('backup/data/snapshot-new')
>>> s.pkg_dir
PosixPath('backup/data/snapshot-new/pkg')
"""
return self.path / "pkg"
@property @property
def root_home_dir(self): def root_home_dir(self):
@ -82,13 +86,13 @@ class Snapshot(Hierarchy):
Example Example
------- -------
>>> s = Snapshot('/tmp/data/snapshot-new') >>> s = Snapshot('backup/data/snapshot-new')
>>> s.root_home_dir >>> s.root_home_dir
PosixPath('/tmp/data/snapshot-new/root') PosixPath('backup/data/snapshot-new/root')
:rtype: path-like object :rtype: path-like object
""" """
return self._root_home_dir return self.path / "root"
# ========== Functions ========== # ========== Functions ==========

View File

@ -10,7 +10,7 @@ from pathlib import Path
from rbackup.hierarchy.snapshot import Snapshot from rbackup.hierarchy.snapshot import Snapshot
# ========== Constants ========== # ========== Constants ==========
TESTING_MODULE = "rbackup.hierarchy.repository" TESTING_MODULE = "rbackup.hierarchy.snapshot"
# ========== Functions ========== # ========== Functions ==========
@ -33,7 +33,8 @@ class TestSnapshot(unittest.TestCase):
def test_boot_dir(self): def test_boot_dir(self):
self.assertEqual( self.assertEqual(
self.test_snapshot.boot_dir, self.snapshot_fullpath / "boot" self.test_snapshot.boot_dir,
self.snapshot_fullpath / "boot" / "loader",
) )
def test_etc_dir(self): def test_etc_dir(self):
@ -46,6 +47,11 @@ class TestSnapshot(unittest.TestCase):
self.test_snapshot.home_dir, self.snapshot_fullpath / "home" self.test_snapshot.home_dir, self.snapshot_fullpath / "home"
) )
def test_pkg_dir(self):
self.assertEqual(
self.test_snapshot.pkg_dir, self.snapshot_fullpath / "pkg"
)
def test_root_home_dir(self): def test_root_home_dir(self):
self.assertEqual( self.assertEqual(
self.test_snapshot.root_home_dir, self.snapshot_fullpath / "root" self.test_snapshot.root_home_dir, self.snapshot_fullpath / "root"