-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing directory path in
FolderData
constructor (#3359)
This will initialize the node and copy over the tree pointed to by the `tree` keyword argument into the node's repository.
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Tests for the `FolderData` class.""" | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import absolute_import | ||
|
||
import io | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
from aiida.backends.testbase import AiidaTestCase | ||
from aiida.orm import FolderData | ||
|
||
|
||
class TestFolderData(AiidaTestCase): | ||
"""Test for the `FolderData` class.""" | ||
|
||
@classmethod | ||
def setUpClass(cls, *args, **kwargs): | ||
super(TestFolderData, cls).setUpClass(*args, **kwargs) | ||
cls.tempdir = tempfile.mkdtemp() | ||
cls.tree = { | ||
'a.txt': u'Content of file A\nWith some newlines', | ||
'b.txt': u'Content of file B without newline', | ||
} | ||
|
||
for filename, content in cls.tree.items(): | ||
with io.open(os.path.join(cls.tempdir, filename), 'w', encoding='utf8') as handle: | ||
handle.write(content) | ||
|
||
@classmethod | ||
def tearDownClass(cls, *args, **kwargs): | ||
shutil.rmtree(cls.tempdir) | ||
|
||
def test_constructor_tree(self): | ||
"""Test the `tree` constructor keyword.""" | ||
node = FolderData(tree=self.tempdir) | ||
self.assertEqual(sorted(node.list_object_names()), sorted(self.tree.keys())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters