Skip to content

Commit

Permalink
actions: Cleanup created directories in compile
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobGM committed Nov 27, 2018
1 parent 3ebb95c commit f97837a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Versioning <http://semver.org/spec/v2.0.0.html>`_.
Fixed
-----

- Astrality now cleans up directories created by `symlink` and `copy` actions
when modules are cleaned up with the `--cleanup` flag.
- Astrality now cleans up directories created by the `compile`, `stow`,
`symlink` and `copy` actions when modules are cleaned up with the `--cleanup` flag.

[1.1.0] - 2018-06-24
====================
Expand Down
1 change: 1 addition & 0 deletions astrality/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def execute(self, dry_run: bool = False) -> Dict[Path, Path]:
)
else:
self.creation_store.backup(path=target_file)
self.creation_store.mkdir(path=target_file.parent)
compiler.compile_template(
template=content_file,
target=target_file,
Expand Down
39 changes: 39 additions & 0 deletions astrality/tests/actions/test_compile_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,42 @@ def test_creation_of_backup(create_temp_files):
# And when cleaning up the module, the backup should be restored
CreatedFiles().cleanup(module='test')
assert target.read_text() == 'original'


def test_cleanup_of_created_directories(create_temp_files, tmpdir):
"""Directories created during compilation should be cleaned up."""
tmpdir = Path(tmpdir)
[template] = create_temp_files(1)

# The target requires two new directories to be created
directory = tmpdir / 'subdir' / 'dir'
target = directory / 'target.tmp'

compile_dict = {
'content': str(template.name),
'target': str(target),
}
compile_action = CompileAction(
options=compile_dict,
directory=template.parent,
replacer=lambda x: x,
context_store={},
creation_store=CreatedFiles().wrapper_for(module='test'),
)

# At first, the target and its two parent directories do not exist
assert not target.exists()
assert not directory.exists()
assert not directory.parent.exists()

# Then, these three paths are created
compile_action.execute()
assert target.exists()
assert directory.exists()
assert directory.parent.exists()

# And then must be cleaned up again
CreatedFiles().cleanup(module='test')
assert not target.exists()
assert not directory.exists()
assert not directory.parent.exists()

0 comments on commit f97837a

Please sign in to comment.