Open beccasaurus opened 5 years ago
It sounds like the issue is that, as captured in the doc, chdir
changes to the specified directory before executing the sample, not before running the test. chdir
is a property of the sample, after all, in the manifest file. So with this behavior, it's expected that printing os.getcwd()
would give you the directory from which the sample-tester is run, whereas call()
should switch to the chdir
directory before calling the sample. (If you had the sample printout os.getcwd()
, it should always give the chdir
directory if one was provided.)
Sounds like what's needed is a way to have the test plan extract a particular sample's chdir
and then cd
to it.
+1
Where "have the test plan extract a particular sample's chdir
and then cd
to it." can use a language built-in to switch the running context safely to that dir (and switch back to the main dir after code evaluation)
If there's no idiomatic block-ish way to eval a bit of code chdir'd, looks like the recommended approach is just to try/finally
program_dir = os.getcwd()
sample_chdir = sample.chdir
try:
os.chdir(sample_chdir)
# eval the things
finally:
os.chdir(program_dir)
Steps to reproduce:
- code: print(os.getcwd())
Expected result:
chdir:
location should be printedActual:
If I
cd
around my system, the value ofos.getcwd()
changes as Icd
where I invoke sample-tester from. This should remain static and should always be the working directory specified in the test'schdir:
Use case example (how I ran into this)
write_file:
to savefile_name: ["output.mp3"]
os.path.exists("output.mp3")
returns false (even though output.mp3 was saved OK)os.getcwd()
is show the directory that I'm currently invoking sample-tester FROM (rather than thechdir:
location)This means that my tests fail unless I
cd
into a very particular directory (which is already configured as thechdir:
)From texttospeech/ library root, where sample tests are typically run from:
Change directory into texttospeech/samples/ (shouldn't need to be in this directory)
Implementation thought: