Revision: 3331
Author: pekka.klarck
Date: Wed May 19 05:00:45 2010
Log: name to files/dirs
http://code.google.com/p/robotframework/source/detail?r=3331

Modified:
 /trunk/src/robot/parsing/newmodel.py
 /trunk/utest/parsing/test_model.py

=======================================
--- /trunk/src/robot/parsing/newmodel.py        Wed May 19 04:06:46 2010
+++ /trunk/src/robot/parsing/newmodel.py        Wed May 19 05:00:45 2010
@@ -28,10 +28,24 @@
     return TestCaseFile(path)


-class TestCaseFile(object):
+class _TestData(object):
+
+    def __init__(self, source):
+        self.source = os.path.abspath(source) if source else None
+
+    @property
+    def name(self):
+        if not self.source:
+            return None
+        name = os.path.splitext(os.path.basename(self.source))[0]
+        name = name.replace('_', ' ')
+        return name.title() if name.islower() else name
+
+
+class TestCaseFile(_TestData):

     def __init__(self, source=None):
-        self.source = source
+        _TestData.__init__(self, source)
         self.setting_table = SettingTable()
         self.variable_table = VariableTable()
         self.testcase_table = TestCaseTable()
@@ -45,10 +59,10 @@
             yield table


-class TestDataDirectory(object):
+class TestDataDirectory(_TestData):

     def __init__(self, source=None):
-        self.source = source
+        _TestData.__init__(self, source)
         self.initfile = None
         self.setting_table = SettingTable()
         self.variable_table = VariableTable()
=======================================
--- /trunk/utest/parsing/test_model.py  Tue May 18 05:28:18 2010
+++ /trunk/utest/parsing/test_model.py  Wed May 19 05:00:45 2010
@@ -20,6 +20,16 @@
         assert_true(isinstance(self.tcf.testcase_table, TestCaseTable))
         assert_true(isinstance(self.tcf.keyword_table, KeywordTable))

+    def test_name(self):
+        assert_none(self.tcf.name)
+        for source, name in [('hello.txt', 'Hello'),
+                             ('hello', 'Hello'),
+                             ('hello_world.tsv', 'Hello World'),
+                             ('HELLO world.htm', 'HELLO world'),
+                             ('HelloWorld.txt', 'HelloWorld')]:
+            self.tcf.source = os.path.abspath(source)
+            assert_equal(self.tcf.name, name)
+
     def test_integration(self):
test_file = StringIO('*** Test Cases *** \nMy test No operation\n')
         TxtReader().read(test_file, TestDataPopulator(self.tcf))

Reply via email to