Re: [PATCH 1/2] Add doctests and integrate them into unittest system Add test for isEfiPartition Add dummy implementation for some file methods Add Mock class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/14/2010 10:06 AM, Martin Sivak wrote:
---
  anaconda                      |    4 +-
  tests/__init__.py             |   14 ++-
  tests/doctests/bootloader.txt |   57 +++++++++
  tests/doctests/language.txt   |    3 +
  tests/doctests/options.txt    |    6 +
  tests/doctests/run_tests.py   |   65 ++++++++++
  tests/doctests/selftest.txt   |   42 +++++++
  tests/mock/__init__.py        |    2 +
  tests/mock/disk.py            |   68 ++++++++++
  tests/mock/mock.py            |  271 +++++++++++++++++++++++++++++++++++++++++
  10 files changed, 524 insertions(+), 8 deletions(-)
  create mode 100644 tests/doctests/__init__.py
  create mode 100644 tests/doctests/bootloader.txt
  create mode 100644 tests/doctests/language.txt
  create mode 100644 tests/doctests/options.txt
  create mode 100755 tests/doctests/run_tests.py
  create mode 100644 tests/doctests/selftest.txt
  create mode 100644 tests/mock/__init__.py
  create mode 100644 tests/mock/disk.py
  create mode 100644 tests/mock/mock.py


Hi Martin,

I think everyone is happy to see new unit tests, so a huge ack in general, with some concrete objections inlined.

diff --git a/tests/doctests/selftest.txt b/tests/doctests/selftest.txt
new file mode 100644
index 0000000..28e9e07
--- /dev/null
+++ b/tests/doctests/selftest.txt
@@ -0,0 +1,42 @@
+>>>  from tests.dummies import O, InitTest
+>>>  1+1
+2
+>>>  2*9
+18
+>>>  raise Exception("lala")
+Traceback (most recent call last):
+...
+Exception: lala
+>>>  Test = InitTest()
+>>>  f = file("/tmp/test.txt", "r")
+Traceback (most recent call last):
+...
+IOError: [Errno 2] No such file or directory: '/tmp/test.txt'
+>>>  f = open("/tmp/test.txt", "w")
+>>>  f.write("test")
+>>>  Test.fs["/tmp/test.txt"]
+''
+>>>  f.flush()
+>>>  Test.fs["/tmp/test.txt"]
+'test'
+>>>  import os
+>>>  f.seek(-2, os.SEEK_CUR)
+>>>  f.write("02")
+>>>  f.close()
+>>>  __testenv__.fs["/tmp/test.txt"]
+'te02'
+>>>  os.path.exists("/tmp/test.txt")
+True
+>>>  os.path.exists("/etc/passwd")
+False
+>>>  os.access('/tmp/test.txt', os.R_OK)
+True
+>>>  os.remove("/tmp/test.txt")
+>>>  os.path.exists("/tmp/test.txt")
+False
+>>>  os.remove("/tmp/test.txt")
+Traceback (most recent call last):
+...
+OSError: [Errno 2] No such file or directory: '/tmp/test.txt'
+>>>  os.access('/tmp/test.txt', os.R_OK)
+False

We talked about this questionable practice of testing mocks (which are part of tests already).

diff --git a/tests/mock/__init__.py b/tests/mock/__init__.py
new file mode 100644
index 0000000..5e2c84d
--- /dev/null
+++ b/tests/mock/__init__.py
@@ -0,0 +1,2 @@
+from disk import *

Please mention at the top of this file what it does and why you need it.

diff --git a/tests/mock/mock.py b/tests/mock/mock.py
new file mode 100644
index 0000000..03871d6
--- /dev/null
+++ b/tests/mock/mock.py
@@ -0,0 +1,271 @@
+# mock.py
+# Test tools for mocking and patching.
+# Copyright (C) 2007-2009 Michael Foord
+# E-mail: fuzzyman AT voidspace DOT org DOT uk
+
+# mock 0.6.0
+# http://www.voidspace.org.uk/python/mock/
+
+# Released subject to the BSD License
+# Please see http://www.voidspace.org.uk/python/license.shtml
+
+# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml
+# Comments, suggestions and bug reports welcome.
+

Just make sure to remove this once mock is properly packaged in fedora.

Ales

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux