def test_exists_true_false(self, exists): exists.return_value = False field = FilenameField(exists=True) with pytest.raises(ValueError): field.validate(MockConfig(), 'file.txt') exists.assert_called_once_with('file.txt')
def test_empty_required(self): field = FilenameField(required=True, exists=True) with pytest.raises(ValueError): field.validate(MockConfig(), '')
def test_empty_not_required(self): field = FilenameField(exists=True) assert field.validate(MockConfig(), '') == ''
def test_file_false(self, isfile): isfile.return_value = False field = FilenameField(exists='file') with pytest.raises(ValueError): field.validate(MockConfig(), 'some-file') isfile.assert_called_once_with('some-file')
def test_file_true(self, isfile): isfile.return_value = True field = FilenameField(exists='file') assert field.validate(MockConfig(), 'some-file') == 'some-file' isfile.assert_called_once_with('some-file')
def test_dir_true(self, isdir): isdir.return_value = True field = FilenameField(exists='dir') assert field.validate(MockConfig(), 'some-dir') == 'some-dir' isdir.assert_called_once_with('some-dir')
def test_exists_false_false(self, exists): exists.return_value = False field = FilenameField(exists=False) assert field.validate(MockConfig(), 'file.txt') == 'file.txt' exists.assert_called_once_with('file.txt')
def test_convert_win_slashes(self): field = FilenameField() assert field.validate(MockConfig(), '/file.txt') == '\\file.txt'
def test_absolute(self): field = FilenameField(startdir=os.getcwd()) assert field.validate(MockConfig(), os.path.sep + 'file.txt') == os.path.sep + 'file.txt'
def test_resolve_relative(self): field = FilenameField(startdir=os.getcwd()) assert field.validate(MockConfig(), 'file.txt') == os.path.join( os.getcwd(), 'file.txt')