@@ -77,7 +77,34 @@ def tearDown(self):
7777 if os .path .exists (self .tempdir ):
7878 shutil .rmtree (self .tempdir , ignore_errors = True )
7979
80- def test_writer (self ):
80+ def test_writer_default_name (self ):
81+ specwriter = SpecWriterCallback ()
82+ path = os .path .abspath (
83+ os .path .dirname (
84+ specwriter .spec_filename ))
85+ self .assertNotEqual (
86+ path ,
87+ self .tempdir ,
88+ "default file not in tempdir" )
89+ self .assertEqual (
90+ path ,
91+ os .path .abspath (os .getcwd ()),
92+ "default file to go in pwd" )
93+
94+ # change the directory
95+ specwriter .spec_filename = os .path .join (
96+ self .tempdir ,
97+ specwriter .spec_filename )
98+
99+ self .assertFalse (
100+ os .path .exists (specwriter .spec_filename ),
101+ "data file not created yet" )
102+ write_stream (specwriter , self .db ["tune_mr" ])
103+ self .assertTrue (
104+ os .path .exists (specwriter .spec_filename ),
105+ "data file created" )
106+
107+ def test_writer_filename (self ):
81108 self .assertTrue (len (self .db ) > 0 , "test data ready" )
82109
83110 testfile = os .path .join (self .tempdir , "tune_mr.dat" )
@@ -94,8 +121,13 @@ def test_writer(self):
94121 self .assertFalse (
95122 os .path .exists (testfile ),
96123 "data file not created yet" )
97- write_stream (
98- specwriter , self .db ["tune_mr" ])
124+ write_stream (specwriter , self .db ["tune_mr" ])
125+ self .assertTrue (os .path .exists (testfile ), "data file created" )
126+
127+ def test_newfile_exists (self ):
128+ testfile = os .path .join (self .tempdir , "tune_mr.dat" )
129+ specwriter = SpecWriterCallback (filename = testfile )
130+ write_stream (specwriter , self .db ["tune_mr" ])
99131 self .assertTrue (os .path .exists (testfile ), "data file created" )
100132
101133 # TODO: #128 do not raise if exists
@@ -107,32 +139,6 @@ def test_writer(self):
107139 finally :
108140 self .assertTrue (raised , "file exists" )
109141
110- specwriter = SpecWriterCallback ()
111- path = os .path .abspath (
112- os .path .dirname (
113- specwriter .spec_filename ))
114- self .assertNotEqual (
115- path ,
116- self .tempdir ,
117- "default file not in tempdir" )
118- self .assertEqual (
119- path ,
120- os .path .abspath (os .getcwd ()),
121- "default file in pwd" )
122-
123- # change the directory
124- specwriter .spec_filename = os .path .join (
125- self .tempdir ,
126- specwriter .spec_filename )
127-
128- self .assertFalse (
129- os .path .exists (specwriter .spec_filename ),
130- "data file not created yet" )
131- write_stream (specwriter , self .db ["tune_mr" ])
132- self .assertTrue (
133- os .path .exists (specwriter .spec_filename ),
134- "data file created" )
135-
136142
137143def suite (* args , ** kw ):
138144 test_list = [
0 commit comments