Revision: 4109
Author: pekka.klarck
Date: Thu Sep 23 07:13:19 2010
Log: 1) better error reporting for get_file_size (issue 672), 2) split its
tests to own suite from misc.txt
http://code.google.com/p/robotframework/source/detail?r=4109
Added:
/trunk/atest/robot/standard_libraries/operating_system/get_file_size.txt
/trunk/atest/testdata/standard_libraries/operating_system/get_file_size.txt
Modified:
/trunk/src/robot/libraries/OperatingSystem.py
=======================================
--- /dev/null
+++
/trunk/atest/robot/standard_libraries/operating_system/get_file_size.txt
Thu Sep 23 07:13:19 2010
@@ -0,0 +1,20 @@
+*** Settings ***
+Suite Setup Run Tests ${EMPTY}
standard_libraries/operating_system/get_file_size.txt
+Force Tags regression jybot pybot
+Resource atest_resource.txt
+
+*** Variables ***
+${TESTFILE} ${TEMPDIR}/robot_temp_file.txt
+
+*** Test Cases ***
+Get File Size
+ ${tc} = Check testcase ${TESTNAME}
+ Check Log Message ${tc.kws[1].msgs[0]} Size of file '<a
href="file://${TESTFILE}">${TESTFILE}</a>' is 0 bytes HTML
+ Check Log Message ${tc.kws[4].msgs[0]} Size of file '<a
href="file://${TESTFILE}">${TESTFILE}</a>' is 1 byte HTML
+ Check Log Message ${tc.kws[7].msgs[0]} Size of file '<a
href="file://${TESTFILE}">${TESTFILE}</a>' is 12 bytes HTML
+
+Get size of non-existing file
+ Check testcase ${TESTNAME}
+
+Get size of directory
+ Check testcase ${TESTNAME}
=======================================
--- /dev/null
+++
/trunk/atest/testdata/standard_libraries/operating_system/get_file_size.txt
Thu Sep 23 07:13:19 2010
@@ -0,0 +1,28 @@
+*** Settings ***
+Library OperatingSystem
+
+*** Variables ***
+${TESTFILE} ${TEMPDIR}/robot_temp_file.txt
+
+*** Test Cases ***
+Get File Size
+ Create File ${TESTFILE}
+ ${size} = Get File Size ${TESTFILE}
+ Should Be Equal ${size} ${0}
+ Create File ${TESTFILE} x
+ ${size} = Get File Size ${TESTFILE}
+ Should Be Equal ${size} ${1}
+ Create File ${TESTFILE} some content
+ ${size} = Get File Size ${TESTFILE}
+ Should Be Equal ${size} ${12}
+ ${size} = Get File Size ${CURDIR}/get_file_size.txt
+ Should Be True 0 < ${size} < 1000
+ [Teardown] Remove FIle ${TESTFILE}
+
+Get size of non-existing file
+ [Documentation] FAIL File '${EXECDIR}${/}non.ex' does not exist.
+ Get File Size non.ex
+
+Get size of directory
+ [Documentation] FAIL File '${CURDIR}' does not exist.
+ Get File Size ${CURDIR}
=======================================
--- /trunk/src/robot/libraries/OperatingSystem.py Mon May 31 05:21:54 2010
+++ /trunk/src/robot/libraries/OperatingSystem.py Thu Sep 23 07:13:19 2010
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-
import os
import sys
import time
@@ -1041,16 +1040,17 @@
mtime = parse_time(mtime)
except DataError, err:
raise RuntimeError("Setting modified time of '%s' failed: %s"
- % (path, err))
+ % (path, err))
os.utime(path, (mtime, mtime))
time.sleep(0.1) # Give os some time to really set these times
tstamp = secs_to_timestamp(mtime, ('-',' ',':'))
self._link("Set modified time of '%%s' to %s" % tstamp, path)
-
def get_file_size(self, path):
"""Returns and logs file size as an integer in bytes"""
path = self._absnorm(path)
+ if not os.path.isfile(path):
+ raise RuntimeError("File '%s' does not exist." % path)
size = os.stat(path).st_size
plural = plural_or_not(size)
self._link("Size of file '%%s' is %d byte%s" % (size, plural),
path)