def test_convert_machine_listing_to_file_entry(self): results = tuple(machine_listings_to_file_entries( parse_machine_listing(SAMPLE_LISTING_1) )) self.assertEqual( FileEntry( 'capmux.tar.z', type='file', size= 25730, date=datetime.datetime(1994, 7, 28, 9, 58, 54, tzinfo=datetime.timezone.utc) ), results[3] )
def test_convert_machine_listing_to_file_entry(self): results = tuple( machine_listings_to_file_entries( parse_machine_listing(SAMPLE_LISTING_1))) self.assertEqual( FileEntry('capmux.tar.z', type='file', size=25730, date=datetime.datetime(1994, 7, 28, 9, 58, 54, tzinfo=datetime.timezone.utc)), results[3])
def test_parse_machine_listing(self): results = parse_machine_listing(SAMPLE_LISTING_1) self.assertEqual( { 'type': 'cdir', 'modify': datetime.datetime(1998, 11, 7, 8, 52, 15, tzinfo=datetime.timezone.utc), 'perm': 'el', 'name': 'tmp' }, results[0] ) self.assertEqual( { 'type': 'cdir', 'modify': datetime.datetime(1998, 11, 7, 8, 52, 15, tzinfo=datetime.timezone.utc), 'perm': 'el', 'name': '/tmp' }, results[1] ) self.assertEqual( { 'type': 'pdir', 'modify': datetime.datetime(1999, 1, 12, 3, 5, 8, tzinfo=datetime.timezone.utc), 'perm': 'el', 'name': '..' }, results[2] ) self.assertEqual( { 'type': 'file', 'size': 25730, 'modify': datetime.datetime(1994, 7, 28, 9, 58, 54, tzinfo=datetime.timezone.utc), 'perm': '', 'name': 'capmux.tar.z' }, results[3] ) self.assertEqual( { 'type': 'file', 'name': 'myfile.txt' }, parse_machine_listing('TYPE=file; myfile.txt')[0] ) self.assertRaises( ValueError, parse_machine_listing, 'modify=123413010204; myfile.txt' ) self.assertRaises( ValueError, parse_machine_listing, 'size=horse; myfile.txt' ) self.assertRaises( ValueError, parse_machine_listing, 'size=123;perm=asdf;myfile.txt' ) self.assertRaises( ValueError, parse_machine_listing, 'size=123;perm=asdf' )
def test_parse_machine_listing(self): results = parse_machine_listing(SAMPLE_LISTING_1) self.assertEqual( { 'type': 'cdir', 'modify': datetime.datetime( 1998, 11, 7, 8, 52, 15, tzinfo=datetime.timezone.utc), 'perm': 'el', 'name': 'tmp' }, results[0]) self.assertEqual( { 'type': 'cdir', 'modify': datetime.datetime( 1998, 11, 7, 8, 52, 15, tzinfo=datetime.timezone.utc), 'perm': 'el', 'name': '/tmp' }, results[1]) self.assertEqual( { 'type': 'pdir', 'modify': datetime.datetime( 1999, 1, 12, 3, 5, 8, tzinfo=datetime.timezone.utc), 'perm': 'el', 'name': '..' }, results[2]) self.assertEqual( { 'type': 'file', 'size': 25730, 'modify': datetime.datetime( 1994, 7, 28, 9, 58, 54, tzinfo=datetime.timezone.utc), 'perm': '', 'name': 'capmux.tar.z' }, results[3]) self.assertEqual({ 'type': 'file', 'name': 'myfile.txt' }, parse_machine_listing('TYPE=file; myfile.txt')[0]) self.assertRaises(ValueError, parse_machine_listing, 'modify=123413010204; myfile.txt') self.assertRaises(ValueError, parse_machine_listing, 'size=horse; myfile.txt') self.assertRaises(ValueError, parse_machine_listing, 'size=123;perm=asdf;myfile.txt') self.assertRaises(ValueError, parse_machine_listing, 'size=123;perm=asdf')