Skip to content

Commit

Permalink
added info.ext
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Apr 28, 2018
1 parent 7122494 commit bb8d29f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ omit = fs/test.py
exclude_lines =
pragma: no cover
if False:
@typing.overload
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.21] - Unreleased

### Added

- Added ext attribute to info

## [2.0.20] - 2018-03-13

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions fs/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ def name(self):
"""
return self.get('basic', 'name')

@property
def ext(self):
# type: () -> Text
"""`str`: the resource extension (including dot).
Example:
>>> info.ext
'.py'
"""
name = self.get('basic', 'name')
basename, dot, ext = name.rpartition('.')
return dot + ext if dot else ''

@property
def is_dir(self):
# type: () -> bool
Expand Down
8 changes: 5 additions & 3 deletions tests/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ def test_basic(self):
# Check simple file
info = Info({
"basic": {
"name": "bar",
"name": "bar.py",
"is_dir": False
}
})
self.assertEqual(info.name, "bar")
self.assertEqual(info.name, "bar.py")
self.assertIsInstance(info.is_dir, bool)
self.assertFalse(info.is_dir)
self.assertEqual(repr(info), "<file 'bar'>")
self.assertEqual(repr(info), "<file 'bar.py'>")
self.assertEqual(info.ext, '.py')

# Check dir
info = Info({
Expand All @@ -85,6 +86,7 @@ def test_basic(self):
})
self.assertTrue(info.is_dir)
self.assertEqual(repr(info), "<dir 'foo'>")
self.assertEqual(info.ext, '')

def test_details(self):
dates = [
Expand Down

0 comments on commit bb8d29f

Please sign in to comment.