Browse Source

Added tests for extension and kind

main
Lakshmi Vyasarajan 14 years ago
parent
commit
fd50a239f6
4 changed files with 50 additions and 7 deletions
  1. +0
    -0
      .gitignore
  2. +1
    -1
      data/templates/basic/layout/base.html
  3. +34
    -6
      hyde/fs.py
  4. +15
    -0
      hyde/tests/test_fs.py

.gitingore → .gitignore View File


+ 1
- 1
data/templates/basic/layout/base.html View File

@@ -46,7 +46,7 @@
{% endblock headjs %} {% endblock headjs %}
{% block endhead %}{% endblock endhead %} {% block endhead %}{% endblock endhead %}
</head> </head>
<body id="{{page.id if page.id else page.base_name}}">
<body id="{{page.id if page.id else page.name_without_extension}}">


<div id="container"> <div id="container">
<header> <header>


+ 34
- 6
hyde/fs.py View File

@@ -4,14 +4,14 @@ python are distributed across modules: os, os.path, fnamtch, shutil and distutil
to make the right choices for common operations to provide a single interface. to make the right choices for common operations to provide a single interface.
""" """


import codecs
import fnmatch
# import codecs
# import fnmatch
import os import os
import shutil
from datetime import datetime
# import shutil
# from datetime import datetime


# pylint: disable-msg=E0611 # pylint: disable-msg=E0611
from distutils import dir_util, file_util
# from distutils import dir_util, file_util


class FS(object): class FS(object):
""" """
@@ -25,4 +25,32 @@ class FS(object):
return self.path return self.path


def __repr__(self): def __repr__(self):
return self.path
return self.path

@property
def name(self):
"""
Returns the name of the FS object with its extension
"""
return os.path.basename(self.path)

@property
def name_without_extension(self):
"""
Returns the name of the FS object without its extension
"""
return os.path.splitext(self.name)[0]

@property
def extension(self):
"""
File's extension prefixed with a dot.
"""
return os.path.splitext(self.path)[1]

@property
def kind(self):
"""
File's extension without a dot prefix.
"""
return self.extension.lstrip(".")

+ 15
- 0
hyde/tests/test_fs.py View File

@@ -12,3 +12,18 @@ def test_representation():
assert str(f) == __file__ assert str(f) == __file__
assert repr(f) == __file__ assert repr(f) == __file__


def test_name():
f = FS(__file__)
assert f.name == "test_fs.py"

def test_name_without_extension():
f = FS(__file__)
assert f.name_without_extension == "test_fs"

def test_extension():
f = FS(__file__)
assert f.extension == ".py"

def test_kind():
f = FS(__file__)
assert f.kind == "py"

Loading…
Cancel
Save