Exemplo n.º 1
0
 def remotedata(self):
     """Create an remote data"""
     from aiida.orm import RemoteData
     rmd = RemoteData()
     rmd.computer = self.localhost
     rmd.set_remote_path(str(self._workdir))
     return rmd
Exemplo n.º 2
0
class TestVerdiDataRemote(AiidaTestCase):
    """
    Testing verdi data remote
    """

    @classmethod
    def setUpClass(cls):
        super(TestVerdiDataRemote, cls).setUpClass()
        user = orm.User.objects.get_default()
        orm.AuthInfo(cls.computer, user).store()

    def setUp(self):
        comp = self.computer
        self.r = RemoteData()
        p = tempfile.mkdtemp()
        self.r.set_remote_path(p)
        with io.open(p + '/file.txt', 'w', encoding='utf8') as fhandle:
            fhandle.write(u'test string')
        self.r.computer = comp
        self.r.store()

        self.cli_runner = CliRunner()

    def test_remoteshowhelp(self):
        output = sp.check_output(['verdi', 'data', 'remote', 'show', '--help'])
        self.assertIn(b'Usage:', output, 'Sub-command verdi data remote show --help failed.')

    def test_remoteshow(self):
        options = [str(self.r.id)]
        res = self.cli_runner.invoke(cmd_remote.remote_show, options, catch_exceptions=False)
        self.assertEqual(res.exit_code, 0, 'The command verdi data remote show did not finish correctly')
        self.assertIn(b'Remote computer name:', res.stdout_bytes,
                      'The string "Remote computer name:" was not found in the'
                      ' output of verdi data remote show')
        self.assertIn(b'Remote folder full path:', res.stdout_bytes,
                      'The string "Remote folder full path:" was not found in the'
                      ' output of verdi data remote show')

    def test_remotelshelp(self):
        output = sp.check_output(['verdi', 'data', 'remote', 'ls', '--help'])
        self.assertIn(b'Usage:', output, 'Sub-command verdi data remote ls --help failed.')

    def test_remotels(self):
        options = ['--long', str(self.r.id)]
        res = self.cli_runner.invoke(cmd_remote.remote_ls, options, catch_exceptions=False)
        self.assertEqual(res.exit_code, 0, 'The command verdi data remote ls did not finish correctly')
        self.assertIn(b'file.txt', res.stdout_bytes, 'The file "file.txt" was not found in the output'
                                                     ' of verdi data remote ls')

    def test_remotecathelp(self):
        output = sp.check_output(['verdi', 'data', 'remote', 'cat', '--help'])
        self.assertIn(b'Usage:', output, 'Sub-command verdi data remote cat --help failed.')

    def test_remotecat(self):
        options = [str(self.r.id), 'file.txt']
        res = self.cli_runner.invoke(cmd_remote.remote_cat, options, catch_exceptions=False)
        self.assertEqual(res.exit_code, 0, 'The command verdi data remote cat did not finish correctly')
        self.assertIn(b'test string', res.stdout_bytes, 'The string "test string" was not found in the output'
                                                        ' of verdi data remote cat file.txt')
Exemplo n.º 3
0
class TestRemoteData(AiidaTestCase):
    """Test for the RemoteData class."""
    @classmethod
    def setUpClass(cls):
        super(TestRemoteData, cls).setUpClass()
        user = User.objects.get_default()
        authinfo = AuthInfo(cls.computer, user)
        authinfo.store()

    def setUp(self):
        """Create a dummy RemoteData on the default computer."""
        self.tmp_path = tempfile.mkdtemp()
        self.remote = RemoteData(computer=self.computer)
        self.remote.set_remote_path(self.tmp_path)

        with io.open(os.path.join(self.tmp_path, 'file.txt'),
                     'w',
                     encoding='utf8') as fhandle:
            fhandle.write(u'test string')

        self.remote.computer = self.computer
        self.remote.store()

    def tearDown(self):
        """Delete the temporary path for the dummy RemoteData node."""
        try:
            shutil.rmtree(self.tmp_path)
        except OSError as exception:
            if exception.errno == errno.ENOENT:
                pass
            elif exception.errno == errno.ENOTDIR:
                os.remove(self.tmp_path)
            else:
                raise IOError(exception)

    def test_clean(self):
        """Try cleaning a RemoteData node."""
        self.assertFalse(self.remote.is_empty)
        self.remote._clean()
        self.assertTrue(self.remote.is_empty)