def test_check_file(self): # only test it can works fc = Namanager() errors = [] etc = { "CHECK_DIRS": [ os.path.realpath( os.path.join(os.path.dirname(__file__), '..', '..')), ], "INCLUDE_FILES": [], "INCLUDE_DIRS": [], "IGNORE_FILES": [], "IGNORE_DIRS": [], "FILE_FORMATS": { "LETTER_CASE": "pascal_case", "SEP": ["dash_to_underscore"], }, "DIR_FORMATS": { "LETTER_CASE": "pascal_case", "SEP": ["dash_to_underscore"], }, } fc.load_settings(etc) fc.check_file(etc['CHECK_DIRS'][0]) for f in fc.get_dict(fc.error_info): expect = f['expect'] actual = f['actual'] helper.append_to_error_if_not_expect_with_msg( errors, len(expect) == len(actual), ("expect: {0}\nactual: {1}".format(expect, actual))) assert errors == [], Exception(helper.get_error_string(errors))
def check(self, **kwargs): settings_json = kwargs.get('settings_json', enums.SETTINGS) COUNT = kwargs.get('count', False) FMT = kwargs.get('fmt', 'json') PRETTY_DUMP = kwargs.get('pretty_dump', False) self._result['unexpected_pairs'] = [] if FMT == 'nodump' else '' for d in settings_json['CHECK_DIRS']: if not util.isdir_casesensitive(d): continue checker = Namanager(settings_json) checker.check(d) if checker.error_info: unexpected_pairs = checker.error_info if COUNT: self._result['errors'].append( 'In folder {0} :'.format(os.path.realpath(d))) self._result['errors'].append( 'FAILED (error={0})'.format(checker.error_info_count)) else: unexpected_pairs = [] if FMT == 'readable': s = "" for pair in checker.get_dict(unexpected_pairs): s += 'expect: {0}\n'.format(pair['expect']) s += 'actual: {0}\n\n'.format(pair['actual']) self._result['unexpected_pairs'] += s elif FMT == 'json': self._result['unexpected_pairs'] += ( checker.get_json(unexpected_pairs, PRETTY_DUMP)) elif FMT == 'xml': self._result['unexpected_pairs'] += ( checker.get_xml(unexpected_pairs, PRETTY_DUMP)) elif FMT == 'nodump': self._result['unexpected_pairs'] += ( checker.get_dict(unexpected_pairs))
def test_get_xml_json_dict(self): fc = Namanager() data = [ { "_id": "5aa7e7247d6d91ca300e1fb3", "index": 0, "guid": "319cb0fe-29b9-4d60-9fde-4e82aee9bc16", "booleans": [True, False], "lists": [[True], [False]], "numbers": { '1': { '1': 1 }, '2': { '2': 2 }, '3': { '3': 3 } }, "list": [213, 3], "isActive": False, "balance": "$2,803.51", "picture": "http://placehold.it/32x32", "age": 31, "eyeColor": "brown", "name": "Esperanza Weeks", "gender": "female", "company": "EZENTIA", "email": "*****@*****.**", "phone": "+1 (930) 533-3206", "address": "653 Division Avenue, Tilleda, Ohio, 5025", "about": "Duis laborum dolor veniam aliqua nostrud velit excepteur qui. Est consectetur incididunt amet nulla pariatur. Do non consequat in occaecat quis esse incididunt. Dolore eu adipisicing esse ad quis et nisi ut ad. Adipisicing amet magna deserunt aliquip nulla laboris cupidatat velit qui ipsum deserunt. Nulla cupidatat eu nisi eu duis nostrud duis sint culpa consectetur fugiat do tempor laboris.", "registered": "2014-11-26T08:32:11 -08:00", "latitude": 83.870374, "longitude": 165.0311, "tags": ["non", "laboris", "sit", "pariatur", "enim", "magna", "qui"], "friends": [{ "id": 0, "name": "Claudine Butler" }, { "id": 1, "name": "Tate Potts" }, { "id": 2, "name": "Clark Franco" }], "greeting": "Hello, Esperanza Weeks! You have 6 unread messages.", "favoriteFruit": "apple" }, # noqa ] for datum in data: # get dict assert helper.is_same_disorderly(datum, fc.get_dict(datum)) # get json actual = json.loads(fc.get_json(datum, False)) assert helper.is_same_disorderly(datum, actual) actual = json.loads(fc.get_json(datum, True)) assert helper.is_same_disorderly(datum, actual) """