Ejemplo n.º 1
0
    def test_get_contents(self):
        """should return contents as bytes from local file"""
        path = os.path.join(self.tmp_dir.path, 'foo.txt')
        subject = LocalFile(path)

        actual = subject.get_contents().getvalue()
        expected = b'bar'

        self.assertEqual(actual, expected)
Ejemplo n.º 2
0
    def test_put_str_contents(self):
        """should store contents passed in as str to local file"""
        path = os.path.join(self.tmp_dir.path, 'my_dir', 'foo.txt')
        subject = LocalFile(path)

        subject.put_contents('baz')
        actual = self.tmp_dir.read('my_dir/foo.txt', encoding='utf-8')
        expected = 'baz'

        self.assertEqual(actual, expected)
Ejemplo n.º 3
0
    def test_attributes(self):
        """should build attribute data to describe file"""
        path = os.path.join(self.tmp_dir.path, 'foo.txt')
        subject = LocalFile(path)

        self.assertEqual(subject.protocol, 'file://')
        self.assertEqual(subject.basename, 'foo.txt')
        self.assertEqual(subject.dir_path, self.tmp_dir.path)
Ejemplo n.º 4
0
    def test_make_local_file_from_windows_path(self):
        """should create a local file when given a windows path"""

        path = 'C:\\Users\\User\\.octorc'
        actual = make_file(path)
        expected = LocalFile(os.path.abspath(path))

        self.assertEqual(actual.__dict__, expected.__dict__)
Ejemplo n.º 5
0
    def test_make_local_file_from_file_url(self):
        """should create a local file when given a file:// protocol url"""

        path = '/path/to/foo.txt'
        url = 'file://' + path
        actual = make_file(url)
        expected = LocalFile(path)

        self.assertEqual(actual.__dict__, expected.__dict__)
Ejemplo n.º 6
0
    def test_make_local_from_relative_path(self):
        """should create a local file when given a relative path"""
        cwd = os.getcwd()

        with TempDirectory() as d:
            os.chdir(d.path)

            rel_path = './foo.txt'
            actual = make_file(rel_path)
            expected = LocalFile(os.path.abspath('./foo.txt'))

            self.assertEqual(actual.__dict__, expected.__dict__)

        os.chdir(cwd)
Ejemplo n.º 7
0
    def test_exists(self):
        """should determine if a local file exists or not"""
        present_path = os.path.join(self.tmp_dir.path, 'foo.txt')
        absent_path = os.path.join(self.tmp_dir.path, 'missing.txt')
        present_subject = LocalFile(present_path)
        absent_subject = LocalFile(absent_path)

        self.assertTrue(present_subject.exists())
        self.assertFalse(absent_subject.exists())