<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division <EOL> import os <EOL> import zipfile <EOL> from twisted . test . test_paths import AbstractFilePathTests <EOL> from twisted . python . zippath import ZipArchive <EOL> from twisted . python . filepath import _coerceToFilesystemEncoding <EOL> def zipit ( dirname , zfname ) : <EOL> """<STR_LIT>""" <EOL> dirname = _coerceToFilesystemEncoding ( '<STR_LIT>' , dirname ) <EOL> zfname = _coerceToFilesystemEncoding ( '<STR_LIT>' , zfname ) <EOL> zf = zipfile . ZipFile ( zfname , "<STR_LIT:w>" ) <EOL> for root , ignored , files , in os . walk ( dirname ) : <EOL> for fname in files : <EOL> fspath = os . path . join ( root , fname ) <EOL> arcpath = os . path . join ( root , fname ) [ len ( dirname ) + <NUM_LIT:1> : ] <EOL> zf . write ( fspath , arcpath ) <EOL> zf . close ( ) <EOL> class ZipFilePathTests ( AbstractFilePathTests ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> AbstractFilePathTests . setUp ( self ) <EOL> zipit ( self . cmn , self . cmn + b'<STR_LIT>' ) <EOL> self . nativecmn = _coerceToFilesystemEncoding ( '<STR_LIT>' , self . cmn ) <EOL> self . path = ZipArchive ( self . cmn + b'<STR_LIT>' ) <EOL> self . root = self . path <EOL> self . all = [ x . replace ( self . cmn , self . cmn + b'<STR_LIT>' ) <EOL> for x in self . all ] <EOL> def test_zipPathRepr ( self ) : <EOL> """<STR_LIT>""" <EOL> child = self . path . child ( "<STR_LIT:foo>" ) <EOL> pathRepr = "<STR_LIT>" % ( <EOL> os . path . abspath ( self . nativecmn + "<STR_LIT>" + os . sep + '<STR_LIT:foo>' ) , ) <EOL> self . assertEqual ( repr ( child ) , pathRepr ) <EOL> relativeCommon = self . nativecmn . replace ( os . getcwd ( ) + os . sep , <EOL> "<STR_LIT>" , <NUM_LIT:1> ) + "<STR_LIT>" <EOL> relpath = ZipArchive ( relativeCommon ) <EOL> child = relpath . child ( "<STR_LIT:foo>" ) <EOL> self . assertEqual ( repr ( child ) , pathRepr ) <EOL> def test_zipPathReprParentDirSegment ( self ) : <EOL> """<STR_LIT>""" <EOL> child = self . path . child ( "<STR_LIT:foo>" ) . child ( "<STR_LIT:..>" ) . child ( "<STR_LIT:bar>" ) <EOL> pathRepr = "<STR_LIT>" % ( <EOL> self . nativecmn + "<STR_LIT>" + os . sep . join ( [ "<STR_LIT>" , "<STR_LIT:foo>" , "<STR_LIT:..>" , "<STR_LIT:bar>" ] ) ) <EOL> self . assertEqual ( repr ( child ) , pathRepr ) <EOL> def test_zipArchiveRepr ( self ) : <EOL> """<STR_LIT>""" <EOL> path = ZipArchive ( self . nativecmn + '<STR_LIT>' ) <EOL> pathRepr = '<STR_LIT>' % ( os . path . abspath ( <EOL> self . nativecmn + '<STR_LIT>' ) , ) <EOL> self . assertEqual ( repr ( path ) , pathRepr ) <EOL> relativeCommon = self . nativecmn . replace ( os . getcwd ( ) + os . sep , <EOL> "<STR_LIT>" , <NUM_LIT:1> ) + "<STR_LIT>" <EOL> relpath = ZipArchive ( relativeCommon ) <EOL> self . assertEqual ( repr ( relpath ) , pathRepr ) </s>
