Commit 8b235196 authored by Brett Cannon's avatar Brett Cannon

Have test_mkalias_relative check that sys.prefix already exists; otherwise test

is pointless.

Also add a note to the docs for the 'test' package that test cases should check
first that any conditions needed in the operating system are met before having
a test run.

Closes bug #1077302.  THanks, Ian Holsman.
parent 3c351f02
...@@ -31,8 +31,10 @@ style; these styles of tests will not be covered. ...@@ -31,8 +31,10 @@ style; these styles of tests will not be covered.
It is preferred that tests for the \module{test} package use the It is preferred that tests for the \module{test} package use the
\refmodule{unittest} module and follow a few guidelines. \refmodule{unittest} module and follow a few guidelines.
One is to have the name of all the test methods start with \samp{test_} as One is to name the test module by starting it with \samp{test_} and end it with
well as the module's name. the name of the module being tested.
The test methods in the test module should start with \samp{test_} and end with
a description of what the method is testing.
This is needed so that the methods are recognized by the test driver as This is needed so that the methods are recognized by the test driver as
test methods. test methods.
Also, no documentation string for the method should be included. Also, no documentation string for the method should be included.
...@@ -109,6 +111,8 @@ This leads to a few guidelines to be followed: ...@@ -109,6 +111,8 @@ This leads to a few guidelines to be followed:
changed in the future. changed in the future.
\item Make sure to clean up after your tests (such as close and remove all \item Make sure to clean up after your tests (such as close and remove all
temporary files). temporary files).
\item If a test is dependent on a specific condition of the operating system
then verify the condition already exists before attempting the test.
\item Import as few modules as possible and do it as soon as possible. \item Import as few modules as possible and do it as soon as possible.
This minimizes external dependencies of tests and also minimizes possible This minimizes external dependencies of tests and also minimizes possible
anomalous behavior from side-effects of importing a module. anomalous behavior from side-effects of importing a module.
......
...@@ -75,6 +75,12 @@ class TestMacostools(unittest.TestCase): ...@@ -75,6 +75,12 @@ class TestMacostools(unittest.TestCase):
os.unlink(TESTFN2) os.unlink(TESTFN2)
except: except:
pass pass
# If the directory doesn't exist, then chances are this is a new
# install of Python so don't create it since the user might end up
# running ``sudo make install`` and creating the directory here won't
# leave it with the proper permissions.
if not os.path.exists(sys.prefix):
return
macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix) macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix)
fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0) fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN)) self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment