def test_filename_option_requires_a_valid_filename(self): option = Options.get('filename') validator = validators.ObjectOptionValueValidator( option, Modes.get('copy')) dirname = os.path.dirname(__file__) with self.assertRaises(ValidationError): validator.validate(document('invalid-file')) with self.assertRaises(ValidationError): validator.validate(document(dirname))
def setUp(self): super().setUp() cwd = os.getcwd() os.chdir('tests/core/fixtures/modes') self.addCleanup(os.chdir, cwd) self.fn = __file__ self.size = os.path.getsize(self.fn) with open(self.fn, 'br') as fp: self.sha256sum = hashlib.sha256(fp.read()).hexdigest() self.mode_class = Modes.get(self.mode) self.mode_schema = '{}-object.json'.format(self.mode) self.default_string_file = '{}_default.txt'.format(self.mode) self.full_string_file = '{}_full.txt'.format(self.mode) self.default_options = None self.default_template = None self.default_metadata = None self.full_options = None self.full_template = None self.full_metadata = None
def test_raises_when_invalid_choice(self): option = Options.get('filesystem') validator = validators.ObjectOptionValueValidator( option, Modes.get('copy')) with self.assertRaises(ValidationError): validator.validate(document('invalid-filesystem'))
def test_invalid_value_raises_error(self): option = Options.get('truncate') validator = validators.ObjectOptionValueValidator( option, Modes.get('copy')) with self.assertRaises(ValidationError): validator.validate(document('not-an-absolut-path'))
def test_empty_value_raises_error_if_required_and_has_no_default(self): option = Options.get('target') validator = validators.ObjectOptionValueValidator( option, Modes.get('copy')) with self.assertRaises(ValidationError): validator.validate(document(''))
def test_empty_value_returns_None_if_option_has_default(self): option = Options.get('format?') validator = validators.ObjectOptionValueValidator( option, Modes.get('copy')) self.assertIsNone(validator.validate(document('')))
def test_valid_value_returns_None(self): option = Options.get('format?') validator = validators.ObjectOptionValueValidator( option, Modes.get('copy')) for value in ['y', 'yes', 'n', 'no']: self.assertIsNone(validator.validate(document(value)))
def test_raises_when_invalid_target_type(self): option = Options.get('target-type') validator = validators.ObjectOptionValueValidator( option, Modes.get('copy')) with self.assertRaises(ValidationError): validator.validate(document('invalid-target-type'))