コード例 #1
0
 def __init__(self, cache_dir=DEFAULT_CACHE_DIR, fslayer=None):
     self._cache_dir = cache_dir
     if fslayer is None:
         fslayer = FSLayer()
     self._fslayer = fslayer
     self.commands = []
     self.subcommands = []
     self.global_opts = []
     self.args_opts = set()
コード例 #2
0
ファイル: test_utils.py プロジェクト: rmoorman/aws-shell
class TestFSLayer(unittest.TestCase):
    # TestFSLayer provides abstractions over the OS.
    # It is one of the only exceptions in the AWS Shell
    # code where it's ok to test by using actual files.
    # All other test code should use FSLayer.
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.temporary_filename = os.path.join(
            self.tempdir, 'tempfilefoo')
        self.fslayer = FSLayer()

    def tearDown(self):
        shutil.rmtree(self.tempdir)

    def test_can_read_file_contents(self):
        with open(self.temporary_filename, 'w') as f:
            f.write('helloworld')

        self.assertEqual(
            self.fslayer.file_contents(self.temporary_filename),
            'helloworld')
        self.assertEqual(
            self.fslayer.file_contents(self.temporary_filename, binary=True),
            b'helloworld')

    def test_file_exists(self):
        self.assertFalse(self.fslayer.file_exists(self.temporary_filename))

        with open(self.temporary_filename, 'w') as f:
            pass

        self.assertTrue(self.fslayer.file_exists(self.temporary_filename))

    def test_file_does_not_exist_error(self):
        with self.assertRaises(FileReadError):
            self.fslayer.file_contents('/tmp/thisdoesnot-exist.asdf')
コード例 #3
0
class TestFSLayer(unittest.TestCase):
    # TestFSLayer provides abstractions over the OS.
    # It is one of the only exceptions in the AWS Shell
    # code where it's ok to test by using actual files.
    # All other test code should use FSLayer.
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.temporary_filename = os.path.join(
            self.tempdir, 'tempfilefoo')
        self.fslayer = FSLayer()

    def tearDown(self):
        shutil.rmtree(self.tempdir)

    def test_can_read_file_contents(self):
        with open(self.temporary_filename, 'w') as f:
            f.write('helloworld')

        self.assertEqual(
            self.fslayer.file_contents(self.temporary_filename),
            'helloworld')
        self.assertEqual(
            self.fslayer.file_contents(self.temporary_filename, binary=True),
            b'helloworld')

    def test_file_exists(self):
        self.assertFalse(self.fslayer.file_exists(self.temporary_filename))

        with open(self.temporary_filename, 'w') as f:
            pass

        self.assertTrue(self.fslayer.file_exists(self.temporary_filename))

    def test_file_does_not_exist_error(self):
        with self.assertRaises(FileReadError):
            self.fslayer.file_contents('/tmp/thisdoesnot-exist.asdf')
コード例 #4
0
ファイル: test_utils.py プロジェクト: rmoorman/aws-shell
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.temporary_filename = os.path.join(
         self.tempdir, 'tempfilefoo')
     self.fslayer = FSLayer()
コード例 #5
0
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.temporary_filename = os.path.join(
         self.tempdir, 'tempfilefoo')
     self.fslayer = FSLayer()