����JFIFXX�����    $.' ",#(7),01444'9=82<.342  2!!22222222222222222222222222222222222222222222222222����"��4�� ���,�PG"Z_�4�˷����kjز�Z�,F+��_z�,�© �����zh6�٨�ic�fu���#ډb���_�N�?��wQ���5-�~�I���8����TK<5o�Iv-�����k�_U_�����~b�M��d����Ӝ�U�Hh��?]��E�w��Q���k�{��_}qFW7HTՑ��Y��F�?_�'ϔ��_�Ջt��=||I ��6�έ"�����D���/[�k�9���Y�8ds|\���Ҿp6�Ҵ���]��.����6�z<�v��@]�i%��$j��~�g��J>��no����pM[me�i$[����s�o�ᘨ�˸ nɜG-�ĨU�ycP�3.DB�li�;��hj���x7Z^�N�h������N3u{�:j�x�힞��#M&��jL P@_���� P��&��o8������9�����@Sz6�t7#O�ߋ �s}Yf�T���lmr����Z)'N��k�۞p����w\�Tȯ?�8`�O��i{wﭹW�[�r�� ��Q4F�׊���3m&L�=��h3����z~��#�\�l :�F,j@�� ʱ�wQT����8�"kJO���6�֚l����}���R�>ډK���]��y����&����p�}b��;N�1�m�r$�|��7�>e�@B�TM*-iH��g�D�)� E�m�|�ؘbҗ�a��Ҿ����t4���o���G��*oCN�rP���Q��@z,|?W[0�����:�n,jWiE��W��$~/�hp\��?��{(�0���+�Y8rΟ�+����>S-S����VN;�}�s?.����� w�9��˟<���Mq4�Wv'��{)0�1mB��V����W[�����8�/<� �%���wT^�5���b��)iM� pg�N�&ݝ��VO~�q���u���9� ����!��J27����$O-���! �:�%H��� ـ����y�ΠM=t{!S�� oK8������t<����è:a������[�����ա�H���~��w��Qz`�po�^ ����Q��n� �,uu�C�$ ^���,������8�#��:�6��e�|~���!�3�3.�\0��q��o�4`.|� ����y�Q�`~;�d�ׯ,��O�Zw�������`73�v�܋�<���Ȏ�� ـ4k��5�K�a�u�=9Yd��$>x�A�&�� j0� ���vF��� Y�|�y��� ~�6�@c��1vOp�Ig����4��l�OD���L����� R���c���j�_�uX6��3?nk��Wy�f;^*B� ��@�~a�`��Eu������+���6�L��.ü>��}y���}_�O�6�͐�:�YrG�X��kG�����l^w���~㒶sy��Iu�!� W ��X��N�7BV��O��!X�2����wvG�R�f�T#�����t�/?���%8�^�W�aT��G�cL�M���I��(J����1~�8�?aT ���]����AS�E��(��*E}� 2��#I/�׍qz��^t�̔���b�Yz4x���t�){ OH��+(E��A&�N�������XT��o��"�XC��'���)}�J�z�p� ��~5�}�^����+�6����w��c��Q�|Lp�d�H��}�(�.|����k��c4^�"�����Z?ȕ ��a<�L�!039C� �Eu�C�F�Ew�ç ;�n?�*o���B�8�bʝ���'#Rqf���M}7����]����s2tcS{�\icTx;�\��7K���P���ʇ Z O-��~��c>"��?�������P��E��O�8��@�8��G��Q�g�a�Վ���󁶠�䧘��_%#r�>�1�z�a��eb��qcPѵ��n���#L��� =��׀t� L�7�`��V���A{�C:�g���e@�w1 Xp3�c3�ġ����p��M"'-�@n4���fG��B3�DJ�8[Jo�ߐ���gK)ƛ��$���� ���8�3�����+���� �����6�ʻ���� ���S�kI�*KZlT _`���?��K����QK�d����B`�s}�>���`��*�>��,*@J�d�oF*����弝��O}�k��s��]��y�ߘ��c1G�V���<=�7��7����6�q�PT��tXԀ�!9*4�4Tހ3XΛex�46���Y��D ����� �BdemDa����\�_l,��G�/���֌7���Y�](�xTt^%�GE�����4�}bT���ڹ�����;Y)���B�Q��u��>J/J �⮶.�XԄ��j�ݳ�+E��d ��r�5�_D�1 ��o�� �B�x�΢�#���<��W�����8���R6�@g�M�.��� dr�D��>(otU��@x=��~v���2� ӣ�d�oBd��3�eO�6�㣷�����ݜ6��6Y��Qz`��S��{���\P�~z m5{J/L��1������<�e�ͅPu�b�]�ϔ���'������f�b� Zpw��c`"��i���BD@:)ִ�:�]��hv�E�w���T�l��P���"Ju�}��وV J��G6��. J/�Qgl߭�e�����@�z�Zev2u�)]կ�����7x���s�M�-<ɯ�c��r�v�����@��$�ޮ}lk���a���'����>x��O\�ZFu>�����ck#��&:��`�$�ai�>2Δ����l���oF[h��lE�ܺ�Πk:)���`�� $[6�����9�����kOw�\|���8}������ބ:��񶐕��I�A1/�=�2[�,�!��.}gN#�u����b��� ~��݊��}34q����d�E��Lc��$��"�[q�U�硬g^��%B �z���r�pJ�ru%v\h1Y�ne`ǥ:g���pQM~�^�Xi� ��`S�:V29.�P���V�?B�k�� AEvw%�_�9C�Q����wKekPؠ�\�;Io d�{ ߞo�c1eP����\� `����E=���@K<�Y���eڼ�J���w����{av�F�'�M�@/J��+9p���|]�����Iw &`��8���&M�hg��[�{��Xj��%��Ӓ�$��(����ʹN���<>�I���RY���K2�NPlL�ɀ)��&e����B+ь����( � �JTx���_?EZ� }@ 6�U���뙢ط�z��dWI�n` D����噥�[��uV��"�G&Ú����2g�}&m��?ċ�"����Om#��������� ��{�ON��"S�X��Ne��ysQ���@Fn��Vg���dX�~nj�]J�<�K]:��FW��b�������62�=��5f����JKw��bf�X�55��~J �%^����:�-�QIE��P��v�nZum� z � ~ə ���� ���ة����;�f��\v���g�8�1��f24;�V���ǔ�)����9���1\��c��v�/'Ƞ�w�������$�4�R-��t���� e�6�/�ġ �̕Ecy�J���u�B���<�W�ַ~�w[B1L۲�-JS΂�{���΃������A��20�c#��@ 0!1@AP"#2Q`$3V�%45a6�FRUq��� ����^7ׅ,$n�������+��F�`��2X'��0vM��p�L=������5��8������u�p~���.�`r�����\���O��,ư�0oS ��_�M�����l���4�kv\JSd���x���SW�<��Ae�IX����������$I���w�:S���y���›R��9�Q[���,�5�;�@]�%���u�@ *ro�lbI �� ��+���%m:�͇ZV�����u�̉����θau<�fc�.����{�4Ա� �Q����*�Sm��8\ujqs]{kN���)qO�y�_*dJ�b�7���yQqI&9�ԌK!�M}�R�;������S�T���1���i[U�ɵz�]��U)V�S6���3$K{�ߊ<�(� E]Զ[ǼENg�����'�\?#)Dkf��J���o��v���'�%ƞ�&K�u�!��b�35LX�Ϸ��63$K�a�;�9>,R��W��3�3� d�JeTYE.Mϧ��-�o�j3+y��y^�c�������VO�9NV\nd�1 ��!͕_)a�v;����թ�M�lWR1��)El��P;��yوÏ�u 3�k�5Pr6<�⒲l�!˞*��u־�n�!�l:����UNW ��%��Chx8vL'��X�@��*��)���̮��ˍ��� ���D-M�+J�U�kvK����+�x8��cY������?�Ԡ��~3mo��|�u@[XeY�C�\Kp�x8�oC�C�&����N�~3-H���� ��MX�s�u<`���~"WL��$8ξ��3���a�)|:@�m�\���^�`�@ҷ)�5p+��6���p�%i)P M���ngc�����#0Aruz���RL+xSS?���ʮ}()#�t��mˇ!��0}}y����<�e� �-ή�Ԩ��X������ MF���ԙ~l L.3���}�V뽺�v�����멬��Nl�)�2����^�Iq��a��M��qG��T�����c3#������3U�Ǎ���}��לS�|qa��ڃ�+���-��2�f����/��bz��ڐ�� �ݼ[2�ç����k�X�2�* �Z�d���J�G����M*9W���s{��w���T��x��y,�in�O�v��]���n����P�$�JB@=4�OTI�n��e�22a\����q�d���%�$��(���:���: /*�K[PR�fr\nڙdN���F�n�$�4�[�� U�zƶ����� �mʋ���,�ao�u 3�z� �x��Kn����\[��VFmbE;�_U��&V�Gg�]L�۪&#n%�$ɯ�dG���D�TI=�%+AB�Ru#��b4�1�»x�cs�YzڙJG��f��Il��d�eF'T� iA��T���uC�$����Y��H?����[!G`}���ͪ� �纤Hv\������j�Ex�K���!���OiƸ�Yj�+u-<���'q����uN�*�r\��+�]���<�wOZ.fp�ێ��,-*)V?j-kÊ#�`�r��dV����(�ݽBk�����G�ƛk�QmUڗe��Z���f}|����8�8��a���i��3'J�����~G_�^���d�8w������ R�`(�~�.��u���l�s+g�bv���W���lGc}��u���afE~1�Ue������Z�0�8�=e�� f@/�jqEKQQ�J��oN��J���W5~M>$6�Lt�;$ʳ{���^��6�{����v6���ķܰg�V�cnn �~z�x�«�,2�u�?cE+Ș�H؎�%�Za�)���X>uW�Tz�Nyo����s���FQƤ��$��*�&�LLXL)�1�" L��eO��ɟ�9=���:t��Z���c��Ž���Y?�ӭV�wv�~,Y��r�ۗ�|�y��GaF�����C�����.�+� ���v1���fήJ�����]�S��T��B��n5sW}y�$��~z�'�c ��8 ��� ,! �p��VN�S��N�N�q��y8z˱�A��4��*��'������2n<�s���^ǧ˭P�Jޮɏ�U�G�L�J�*#��<�V��t7�8����TĜ>��i}K%,���)[��z�21z ?�N�i�n1?T�I�R#��m-�����������������1����lA�`��fT5+��ܐ�c�q՝��ʐ��,���3�f2U�եmab��#ŠdQ�y>\��)�SLY����w#��.���ʑ�f��� ,"+�w�~�N�'�c�O�3F�������N<���)j��&��,-� �љ���֊�_�zS���TǦ����w�>��?�������n��U仆�V���e�����0���$�C�d���rP �m�׈e�Xm�Vu� �L��.�bֹ��� �[Դaզ���*��\y�8�Է:�Ez\�0�Kq�C b��̘��cө���Q��=0Y��s�N��S.���3.���O�o:���#���v7�[#߫ ��5�܎�L���Er4���9n��COWlG�^��0k�%<���ZB���aB_���������'=��{i�v�l�$�uC���mƎҝ{�c㱼�y]���W�i ��ߧc��m�H� m�"�"�����;Y�ߝ�Z�Ǔ�����:S#��|}�y�,/k�Ld� TA�(�AI$+I3��;Y*���Z��}|��ӧO��d�v��..#:n��f>�>���ȶI�TX��� 8��y����"d�R�|�)0���=���n4��6ⲑ�+��r<�O�܂~zh�z����7ܓ�HH�Ga롏���nCo�>������a ���~]���R���̲c?�6(�q�;5%� |�uj�~z8R=X��I�V=�|{v�Gj\gc��q����z�؋%M�ߍ����1y��#��@f^���^�>N�����#x#۹��6�Y~�?�dfPO��{��P�4��V��u1E1J �*|���%���JN��`eWu�zk M6���q t[�� ��g�G���v��WIG��u_ft����5�j�"�Y�:T��ɐ���*�;� e5���4����q$C��2d�}���� _S�L#m�Yp��O�.�C�;��c����Hi#֩%+) �Ӎ��ƲV���SYź��g |���tj��3�8���r|���V��1#;.SQ�A[���S������#���`n�+���$��$I �P\[�@�s��(�ED�z���P��])8�G#��0B��[ى��X�II�q<��9�~[Z멜�Z�⊔IWU&A>�P~�#��dp<�?����7���c��'~���5 ��+$���lx@�M�dm��n<=e�dyX��?{�|Aef ,|n3�<~z�ƃ�uۧ�����P��Y,�ӥQ�*g�#먙R�\���;T��i,��[9Qi歉����c>]9�� ��"�c��P�� �Md?٥��If�ت�u��k��/����F��9�c*9��Ǎ:�ØF���z�n*�@|I�ށ9����N3{'��[�'ͬ�Ҳ4��#}��!�V� Fu��,�,mTIk���v C�7v���B�6k�T9��1�*l� '~��ƞF��lU��'�M ����][ΩũJ_�{�i�I�n��$���L�� j��O�dx�����kza۪��#�E��Cl����x˘�o�����V���ɞ�ljr��)�/,�߬h�L��#��^��L�ф�,íMƁe�̩�NB�L�����iL����q�}��(��q��6IçJ$�W�E$��:������=#����(�K�B����zђ <��K(�N�۫K�w��^O{!����)�H���>x�������lx�?>Պ�+�>�W���,Ly!_�D���Ō�l���Q�!�[ �S����J��1��Ɛ�Y}��b,+�Lo�x�ɓ)����=�y�oh�@�꥟/��I��ѭ=��P�y9��� �ۍYӘ�e+�p�Jnϱ?V\SO%�(�t� ���=?MR�[Ș�����d�/ ��n�l��B�7j� ��!�;ӥ�/�[-���A�>�dN�sLj ��,ɪv��=1c�.SQ�O3�U���ƀ�ܽ�E����������̻��9G�ϷD�7(�}��Ävӌ\�y�_0[w ���<΍>����a_��[0+�L��F.�޺��f�>oN�T����q;���y\��bՃ��y�jH�<|q-eɏ�_?_9+P���Hp$�����[ux�K w�Mw��N�ی'$Y2�=��q���KB��P��~������Yul:�[<����F1�2�O���5=d����]Y�sw:���Ϯ���E��j,_Q��X��z`H1,#II ��d�wr��P˂@�ZJV����y$�\y�{}��^~���[:N����ߌ�U�������O��d�����ؾe��${p>G��3c���Ė�lʌ�� ת��[��`ϱ�-W����dg�I��ig2��� ��}s ��ؤ(%#sS@���~���3�X�nRG�~\jc3�v��ӍL��M[JB�T��s3}��j�Nʖ��W����;7��ç?=X�F=-�=����q�ߚ���#���='�c��7���ڑW�I(O+=:uxq�������������e2�zi+�kuG�R��������0�&e�n���iT^J����~\jy���p'dtG��s����O��3����9* �b#Ɋ�� p������[Bws�T�>d4�ۧs���nv�n���U���_�~,�v����ƜJ1��s�� �QIz��)�(lv8M���U=�;����56��G���s#�K���MP�=��LvyGd��}�VwWBF�'�à �?MH�U�g2�� ����!�p�7Q��j��ڴ����=��j�u��� Jn�A s���uM������e��Ɔ�Ҕ�!)'��8Ϣ�ٔ��ޝ(��Vp���צ֖d=�IC�J�Ǡ{q������kԭ�߸���i��@K����u�|�p=..�*+����x�����z[Aqġ#s2a�Ɗ���RR�)*HRsi�~�a &f��M��P����-K�L@��Z��Xy�'x�{}��Zm+���:�)�) IJ�-i�u���� ���ܒH��'�L(7�y�GӜq���� j��� 6ߌg1�g�o���,kر���tY�?W,���p���e���f�OQS��!K�۟cҒA�|ս�j�>��=⬒��˧L[�� �߿2JaB~R��u�:��Q�] �0H~���]�7��Ƽ�I���(}��cq '�ήET���q�?f�ab���ӥvr� �)o��-Q��_'����ᴎo��K������;��V���o��%���~OK ����*��b�f:���-ťIR��`B�5!RB@���ï�� �u �̯e\�_U�_������� g�ES��3�������QT��a����x����U<~�c?�*�#]�MW,[8O�a�x��]�1bC|踤�P��lw5V%�)�{t�<��d��5���0i�XSU��m:��Z�┵�i�"��1�^B�-��P�hJ��&)O��*�D��c�W��vM��)����}���P��ܗ-q����\mmζZ-l@�}��a��E�6��F�@��&Sg@���ݚ�M����� ȹ 4����#p�\H����dYDo�H���"��\��..R�B�H�z_�/5˘����6��KhJR��P�mƶi�m���3�,#c�co��q�a)*Pt����R�m�k�7x�D�E�\Y�閣_X�<���~�)���c[[�BP����6�Yq���S��0����%_����;��Àv�~�| VS؇ ��'O0��F0��\���U�-�d@�����7�SJ*z��3n��y��P����O���������m�~�P�3|Y��ʉr#�C�<�G~�.,! ���bqx���h~0=��!ǫ�jy����l�O,�[B��~��|9��ٱ����Xly�#�i�B��g%�S��������tˋ���e���ې��\[d�t)��.+u�|1 ������#�~Oj����hS�%��i.�~X���I�H�m��0n���c�1uE�q��cF�RF�o���7� �O�ꮧ� ���ۛ{��ʛi5�rw?׌#Qn�TW��~?y$��m\�\o����%W� ?=>S�N@�� �Ʈ���R����N�)�r"C�:��:����� �����#��qb��Y�. �6[��2K����2u�Ǧ�HYR��Q�MV��� �G�$��Q+.>�����nNH��q�^��� ����q��mM��V��D�+�-�#*�U�̒ ���p욳��u:�������IB���m���PV@O���r[b= �� ��1U�E��_Nm�yKbN�O���U�}�the�`�|6֮P>�\2�P�V���I�D�i�P�O;�9�r�mAHG�W�S]��J*�_�G��+kP�2����Ka�Z���H�'K�x�W�MZ%�O�YD�Rc+o��?�q��Ghm��d�S�oh�\�D�|:W������UA�Qc yT�q������~^�H��/��#p�CZ���T�I�1�ӏT����4��"�ČZ�����}��`w�#�*,ʹ�� ��0�i��課�Om�*�da��^gJ݅{���l�e9uF#T�ֲ��̲�ٞC"�q���ߍ ոޑ�o#�XZTp����@ o�8��(jd��xw�]�,f���`~�|,s��^����f�1���t��|��m�򸄭/ctr��5s��7�9Q�4�H1꠲BB@l9@���C�����+�wp�xu�£Yc�9��?`@#�o�mH�s2��)�=��2�.�l����jg�9$�Y�S�%*L������R�Y������7Z���,*=�䷘$�������arm�o�ϰ���UW.|�r�uf����IGw�t����Zwo��~5 ��YյhO+=8fF�)�W�7�L9lM�̘·Y���֘YLf�큹�pRF���99.A �"wz��=E\Z���'a� 2��Ǚ�#;�'}�G���*��l��^"q��+2FQ� hj��kŦ��${���ޮ-�T�٭cf�|�3#~�RJ����t��$b�(R��(����r���dx� >U b�&9,>���%E\� Ά�e�$��'�q't��*�א���ެ�b��-|d���SB�O�O��$�R+�H�)�܎�K��1m`;�J�2�Y~9��O�g8=vqD`K[�F)k�[���1m޼c��n���]s�k�z$@��)!I �x՝"v��9=�ZA=`Ɠi �:�E��)`7��vI��}d�YI�_ �o�:ob���o ���3Q��&D&�2=�� �Ά��;>�h����y.*ⅥS������Ӭ�+q&����j|UƧ����}���J0��WW< ۋS�)jQR�j���Ư��rN)�Gű�4Ѷ(�S)Ǣ�8��i��W52���No˓� ۍ%�5brOn�L�;�n��\G����=�^U�dI���8$�&���h��'���+�(������cȁ߫k�l��S^���cƗjԌE�ꭔ��gF���Ȓ��@���}O���*;e�v�WV���YJ\�]X'5��ղ�k�F��b 6R�o՜m��i N�i����>J����?��lPm�U��}>_Z&�KK��q�r��I�D�Չ~�q�3fL�:S�e>���E���-G���{L�6p�e,8��������QI��h��a�Xa��U�A'���ʂ���s�+טIjP�-��y�8ۈZ?J$��W�P� ��R�s�]��|�l(�ԓ��sƊi��o(��S0��Y� 8�T97.�����WiL��c�~�dxc�E|�2!�X�K�Ƙਫ਼�$((�6�~|d9u+�qd�^3�89��Y�6L�.I�����?���iI�q���9�)O/뚅����O���X��X�V��ZF[�یgQ�L��K1���RҖr@v�#��X�l��F���Нy�S�8�7�kF!A��sM���^rkp�jP�DyS$N���q��nxҍ!U�f�!eh�i�2�m���`�Y�I�9r�6� �TF���C}/�y�^���Η���5d�'��9A-��J��>{�_l+�`��A���[�'��յ�ϛ#w:݅�%��X�}�&�PSt�Q�"�-��\縵�/����$Ɨh�Xb�*�y��BS����;W�ջ_mc�����vt?2}1�;qS�d�d~u:2k5�2�R�~�z+|HE!)�Ǟl��7`��0�<�,�2*���Hl-��x�^����'_TV�gZA�'j� ^�2Ϊ��N7t�����?w�� �x1��f��Iz�C-Ȗ��K�^q�;���-W�DvT�7��8�Z�������� hK�(P:��Q- �8�n�Z���܃e貾�<�1�YT<�,�����"�6{/ �?�͟��|1�:�#g��W�>$����d��J��d�B��=��jf[��%rE^��il:��B���x���Sּ�1հ��,�=��*�7 fcG��#q� �eh?��2�7�����,�!7x��6�n�LC�4x��},Geǝ�tC.��vS �F�43��zz\��;QYC,6����~;RYS/6���|2���5���v��T��i����������mlv��������&� �nRh^ejR�LG�f���? �ۉҬܦƩ��|��Ȱ����>3����!v��i�ʯ�>�v��オ�X3e���_1z�Kȗ\<������!�8���V��]��?b�k41�Re��T�q��mz��TiOʦ�Z��Xq���L������q"+���2ۨ��8}�&N7XU7Ap�d�X��~�׿��&4e�o�F��� �H����O���č�c�� 懴�6���͉��+)��v;j��ݷ�� �UV�� i��� j���Y9GdÒJ1��詞�����V?h��l����l�cGs�ځ�������y�Ac�����\V3�? �� ܙg�>qH�S,�E�W�[�㺨�uch�⍸�O�}���a��>�q�6�n6����N6�q������N ! 1AQaq�0@����"2BRb�#Pr���3C`��Scst���$4D���%Td�� ?���N����a��3��m���C���w��������xA�m�q�m���m������$����4n淿t'��C"w��zU=D�\R+w�p+Y�T�&�պ@��ƃ��3ޯ?�Aﶂ��aŘ���@-�����Q�=���9D��ռ�ѻ@��M�V��P��܅�G5�f�Y<�u=,EC)�<�Fy'�"�&�չ�X~f��l�KԆV��?�� �W�N����=(� �;���{�r����ٌ�Y���h{�١������jW����P���Tc�����X�K�r��}���w�R��%��?���E��m�� �Y�q|����\lEE4���r���}�lsI�Y������f�$�=�d�yO����p�����yBj8jU�o�/�S��?�U��*������ˍ�0������u�q�m [�?f����a�� )Q�>����6#������� ?����0UQ����,IX���(6ڵ[�DI�MNލ�c&���υ�j\��X�R|,4��� j������T�hA�e��^���d���b<����n�� �즇�=!���3�^�`j�h�ȓr��jẕ�c�,ٞX����-����a�ﶔ���#�$��]w�O��Ӫ�1y%��L�Y<�wg#�ǝ�̗`�x�xa�t�w��»1���o7o5��>�m뭛C���Uƃߜ}�C���y1Xνm�F8�jI���]����H���ۺиE@I�i;r�8ӭ����V�F�Շ| ��&?�3|x�B�MuS�Ge�=Ӕ�#BE5G�����Y!z��_e��q�р/W>|-�Ci߇�t�1ޯќd�R3�u��g�=0 5��[?�#͏��q�cf���H��{ ?u�=?�?ǯ���}Z��z���hmΔ�BFTW�����<�q�(v� ��!��z���iW]*�J�V�z��gX֧A�q�&��/w���u�gYӘa���; �i=����g:��?2�dž6�ى�k�4�>�Pxs����}������G�9��3 ���)gG�R<>r h�$��'nc�h�P��Bj��J�ҧH� -��N1���N��?��~��}-q!=��_2hc�M��l�vY%UE�@|�v����M2�.Y[|y�"Eï��K�ZF,�ɯ?,q�?v�M 80jx�"�;�9vk�����+ ֧�� �ȺU��?�%�vcV��mA�6��Qg^M����A}�3�nl� QRN�l8�kkn�'�����(��M�7m9و�q���%ޟ���*h$Zk"��$�9��: �?U8�Sl��,,|ɒ��xH(ѷ����Gn�/Q�4�P��G�%��Ա8�N��!� �&�7�;���eKM7�4��9R/%����l�c>�x;������>��C�:�����t��h?aKX�bhe�ᜋ^�$�Iհ �hr7%F$�E��Fd���t��5���+�(M6�t����Ü�UU|zW�=a�Ts�Tg������dqP�Q����b'�m���1{|Y����X�N��b �P~��F^F:����k6�"�j!�� �I�r�`��1&�-$�Bevk:y���#yw��I0��x��=D�4��tU���P�ZH��ڠ底taP��6����b>�xa����Q�#� WeF��ŮNj�p�J* mQ�N����*I�-*�ȩ�F�g�3 �5��V�ʊ�ɮ�a��5F���O@{���NX��?����H�]3��1�Ri_u��������ѕ�� ����0��� F��~��:60�p�͈�S��qX#a�5>���`�o&+�<2�D����: �������ڝ�$�nP���*)�N�|y�Ej�F�5ټ�e���ihy�Z �>���k�bH�a�v��h�-#���!�Po=@k̆IEN��@��}Ll?j�O������߭�ʞ���Q|A07x���wt!xf���I2?Z��<ץ�T���cU�j��]��陎Ltl �}5�ϓ��$�,��O�mˊ�;�@O��jE��j(�ا,��LX���LO���Ц�90�O �.����a��nA���7������j4 ��W��_ٓ���zW�jcB������y՗+EM�)d���N�g6�y1_x��p�$Lv:��9�"z��p���ʙ$��^��JԼ*�ϭ����o���=x�Lj�6�J��u82�A�H�3$�ٕ@�=Vv�]�'�qEz�;I˼��)��=��ɯ���x �/�W(V���p�����$ �m�������u�����񶤑Oqˎ�T����r��㠚x�sr�GC��byp�G��1ߠ�w e�8�$⿄����/�M{*}��W�]˷.�CK\�ުx���/$�WPw���r� |i���&�}�{�X� �>��$-��l���?-z���g����lΆ���(F���h�vS*���b���߲ڡn,|)mrH[���a�3�ר�[1��3o_�U�3�TC�$��(�=�)0�kgP���� ��u�^=��4 �WYCҸ:��vQ�ר�X�à��tk�m,�t*��^�,�}D*� �"(�I��9R����>`�`��[~Q]�#af��i6l��8���6�:,s�s�N6�j"�A4���IuQ��6E,�GnH��zS�HO�uk�5$�I�4��ؤ�Q9�@��C����wp�BGv[]�u�Ov���0I4���\��y�����Q�Ѹ��~>Z��8�T��a��q�ޣ;z��a���/��S��I:�ܫ_�|������>=Z����8:�S��U�I�J��"IY���8%b8���H��:�QO�6�;7�I�S��J��ҌAά3��>c���E+&jf$eC+�z�;��V����� �r���ʺ������my�e���aQ�f&��6�ND��.:��NT�vm�<- u���ǝ\MvZY�N�NT��-A�>jr!S��n�O 1�3�Ns�%�3D@���`������ܟ 1�^c<���� �a�ɽ�̲�Xë#�w�|y�cW�=�9I*H8�p�^(4���՗�k��arOcW�tO�\�ƍR��8����'�K���I�Q�����?5�>[�}��yU�ײ -h��=��% q�ThG�2�)���"ו3]�!kB��*p�FDl�A���,�eEi�H�f�Ps�����5�H:�Փ~�H�0Dت�D�I����h�F3�������c��2���E��9�H��5�zԑ�ʚ�i�X�=:m�xg�hd(�v����׊�9iS��O��d@0ڽ���:�p�5�h-��t�&���X�q�ӕ,��ie�|���7A�2���O%P��E��htj��Y1��w�Ѓ!����  ���� ࢽ��My�7�\�a�@�ţ�J �4�Ȼ�F�@o�̒?4�wx��)��]�P��~�����u�����5�����7X ��9��^ܩ�U;Iꭆ 5 �������eK2�7(�{|��Y׎ �V��\"���Z�1� Z�����}��(�Ǝ"�1S���_�vE30>���p;� ΝD��%x�W�?W?v����o�^V�i�d��r[��/&>�~`�9Wh��y�;���R��� ;;ɮT��?����r$�g1�K����A��C��c��K��l:�'��3 c�ﳯ*"t8�~l��)���m��+U,z��`(�>yJ�?����h>��]��v��ЍG*�{`��;y]��I�T� ;c��NU�fo¾h���/$���|NS���1�S�"�H��V���T���4��uhǜ�]�v;���5�͠x��'C\�SBpl���h}�N����� A�Bx���%��ޭ�l��/����T��w�ʽ]D�=����K���ž�r㻠l4�S�O?=�k �M:� ��c�C�a�#ha���)�ѐxc�s���gP�iG��{+���x���Q���I= �� z��ԫ+ �8"�k�ñ�j=|����c ��y��CF��/��*9ж�h{ �?4�o� ��k�m�Q�N�x��;�Y��4膚�a�w?�6�>e]�����Q�r�:����g�,i"�����ԩA�*M�<�G��b�if��l^M��5� �Ҩ�{����6J��ZJ�����P�*�����Y���ݛu�_4�9�I8�7���������,^ToR���m4�H��?�N�S�ѕw��/S��甍�@�9H�S�T��t�ƻ���ʒU��*{Xs�@����f�����֒Li�K{H�w^���������Ϥm�tq���s� ���ք��f:��o~s��g�r��ט� �S�ѱC�e]�x���a��) ���(b-$(�j>�7q�B?ӕ�F��hV25r[7 Y� }L�R��}����*sg+��x�r�2�U=�*'WS��ZDW]�WǞ�<��叓���{�$�9Ou4��y�90-�1�'*D`�c�^o?(�9��u���ݐ��'PI&� f�Jݮ�������:wS����jfP1F:X �H�9dԯ���˝[�_54 �}*;@�ܨ�� ð�yn�T���?�ןd�#���4rG�ͨ��H�1�|-#���Mr�S3��G�3�����)�.᧏3v�z֑��r����$G"�`j �1t��x0<Ɔ�Wh6�y�6��,œ�Ga��gA����y��b��)��h�D��ß�_�m��ü �gG;��e�v��ݝ�nQ� ��C����-�*��o���y�a��M��I�>�<���]obD��"�:���G�A��-\%LT�8���c�)��+y76���o�Q�#*{�(F�⽕�y����=���rW�\p���۩�c���A���^e6��K������ʐ�cVf5$�'->���ՉN"���F�"�UQ@�f��Gb~��#�&�M=��8�ט�JNu9��D��[̤�s�o�~������ G��9T�tW^g5y$b��Y'��س�Ǵ�=��U-2 #�MC�t(�i� �lj�@Q 5�̣i�*�O����s�x�K�f��}\��M{E�V�{�υ��Ƈ�����);�H����I��fe�Lȣr�2��>��W�I�Ȃ6������i��k�� �5�YOxȺ����>��Y�f5'��|��H+��98pj�n�.O�y�������jY��~��i�w'������l�;�s�2��Y��:'lg�ꥴ)o#'Sa�a�K��Z� �m��}�`169�n���"���x��I ��*+� }F<��cГ���F�P�������ֹ*�PqX�x۩��,� ��N�� �4<-����%����:��7����W���u�`����� $�?�I��&����o��o��`v�>��P��"��l���4��5'�Z�gE���8���?��[�X�7(��.Q�-��*���ތL@̲����v��.5���[��=�t\+�CNܛ��,g�SQnH����}*F�G16���&:�t��4ُ"A��̣��$�b �|����#rs��a�����T�� ]�<�j��BS�('$�ɻ� �wP;�/�n��?�ݜ��x�F��yUn�~mL*-�������Xf�wd^�a�}��f�,=t�׵i�.2/wpN�Ep8�OР���•��R�FJ� 55TZ��T �ɭ�<��]��/�0�r�@�f��V��V����Nz�G��^���7hZi����k��3�,kN�e|�vg�1{9]_i��X5y7� 8e]�U����'�-2,���e"����]ot�I��Y_��n�(JҼ��1�O ]bXc���Nu�No��pS���Q_���_�?i�~�x h5d'�(qw52] ��'ޤ�q��o1�R!���`ywy�A4u���h<קy���\[~�4�\ X�Wt/� 6�����n�F�a8��f���z �3$�t(���q��q�x��^�XWeN'p<-v�!�{�(>ӽDP7��ո0�y)�e$ٕv�Ih'Q�EA�m*�H��RI��=:��� ���4牢) �%_iN�ݧ�l]� �Nt���G��H�L��� ɱ�g<���1V�,�J~�ٹ�"K��Q�� 9�HS�9�?@��k����r�;we݁�]I�!{ �@�G�[�"��`���J:�n]�{�cA�E����V��ʆ���#��U9�6����j�#Y�m\��q�e4h�B�7��C�������d<�?J����1g:ٳ���=Y���D�p�ц� ׈ǔ��1�]26؜oS�'��9�V�FVu�P�h�9�xc�oq�X��p�o�5��Ա5$�9W�V(�[Ak�aY錎qf;�'�[�|���b�6�Ck��)��#a#a˙��8���=äh�4��2��C��4tm^ �n'c���]GQ$[Wҿ��i���vN�{Fu ��1�gx��1┷���N�m��{j-,��x�� Ūm�ЧS�[�s���Gna���䑴�� x�p 8<������97�Q���ϴ�v�aϚG��Rt�Һ׈�f^\r��WH�JU�7Z���y)�vg=����n��4�_)y��D'y�6�]�c�5̪�\� �PF�k����&�c;��cq�$~T�7j ���nç]�<�g ":�to�t}�159�<�/�8������m�b�K#g'I'.W�����6��I/��>v��\�MN��g���m�A�yQL�4u�Lj�j9��#44�t��l^�}L����n��R��!��t��±]��r��h6ٍ>�yҏ�N��fU�� ���� Fm@�8}�/u��jb9������he:A�y�ծw��GpΧh�5����l}�3p468��)U��d��c����;Us/�֔�YX�1�O2��uq�s��`hwg�r~�{ R��mhN��؎*q 42�*th��>�#���E����#��Hv�O����q�}�����6�e��\�,Wk�#���X��b>��p}�դ��3���T5��†��6��[��@�P�y*n��|'f�֧>�lư΂�̺����SU�'*�q�p�_S�����M�� '��c�6�����m�� ySʨ;M��r���Ƌ�m�Kxo,���Gm�P��A�G�:��i��w�9�}M(�^�V��$ǒ�ѽ�9���|���� �a����J�SQ�a���r�B;����}���ٻ֢�2�%U���c�#�g���N�a�ݕ�'�v�[�OY'��3L�3�;,p�]@�S��{ls��X�'���c�jw�k'a�.��}�}&�� �dP�*�bK=ɍ!����;3n�gΊU�ߴmt�'*{,=SzfD� A��ko~�G�aoq�_mi}#�m�������P�Xhύ����mxǍ�΂���巿zf��Q���c���|kc�����?���W��Y�$���_Lv����l߶��c���`?����l�j�ݲˏ!V��6����U�Ђ(A���4y)H���p�Z_�x��>���e��R��$�/�`^'3qˏ�-&Q�=?��CFVR �D�fV�9��{�8g�������n�h�(P"��6�[�D���< E�����~0<@�`�G�6����Hг�cc�� �c�K.5��D��d�B���`?�XQ��2��ٿyqo&+�1^� DW�0�ꊩ���G�#��Q�nL3��c���������/��x ��1�1[y�x�პCW��C�c�UĨ80�m�e�4.{�m��u���I=��f�����0QRls9���f���������9���~f�����Ǩ��a�"@�8���ȁ�Q����#c�ic������G��$���G���r/$W�(��W���V�"��m�7�[m�A�m����bo��D� j����۳� l���^�k�h׽����� ��#� iXn�v��eT�k�a�^Y�4�BN��ĕ��0 !01@Q"2AaPq3BR������?���@4�Q�����T3,���㺠�W�[=JK�Ϟ���2�r^7��vc�:�9 �E�ߴ�w�S#d���Ix��u��:��Hp��9E!�� V 2;73|F��9Y���*ʬ�F��D����u&���y؟��^EA��A��(ɩ���^��GV:ݜDy�`��Jr29ܾ�㝉��[���E;Fzx��YG��U�e�Y�C���� ����v-tx����I�sם�Ę�q��Eb�+P\ :>�i�C'�;�����k|z�رn�y]�#ǿb��Q��������w�����(�r|ӹs��[�D��2v-%��@;�8<a���[\o[ϧw��I!��*0�krs)�[�J9^��ʜ��p1)� "��/_>��o��<1����A�E�y^�C��`�x1'ܣn�p��s`l���fQ��):�l����b>�Me�jH^?�kl3(�z:���1ŠK&?Q�~�{�ٺ�h�y���/�[��V�|6��}�KbX����mn[-��7�5q�94�������dm���c^���h� X��5��<�eޘ>G���-�}�دB�ޟ� ��|�rt�M��V+�]�c?�-#ڛ��^ǂ}���Lkr���O��u�>�-D�ry� D?:ޞ�U��ǜ�7�V��?瓮�"�#���r��չģVR;�n���/_� ؉v�ݶe5d�b9��/O��009�G���5n�W����JpA�*�r9�>�1��.[t���s�F���nQ� V 77R�]�ɫ8����_0<՜�IF�u(v��4��F�k�3��E)��N:��yڮe��P�`�1}�$WS��J�SQ�N�j�ٺ��޵�#l���ј(�5=��5�lǏmoW�v-�1����v,W�mn��߀$x�<����v�j(����c]��@#��1������Ǔ���o'��u+����;G�#�޸��v-lη��/(`i⣍Pm^���ԯ̾9Z��F��������n��1��� ��]�[��)�'������:�֪�W��FC����� �B9،!?���]��V��A�Վ�M��b�w��G F>_DȬ0¤�#�QR�[V��kz���m�w�"��9ZG�7'[��=�Q����j8R?�zf�\a�=��O�U����*oB�A�|G���2�54 �p��.w7� �� ��&������ξxGHp� B%��$g�����t�Џ򤵍z���HN�u�Я�-�'4��0��;_��3 !01"@AQa2Pq#3BR������?��ʩca��en��^��8���<�u#��m*08r��y�N"�<�Ѳ0��@\�p��� �����Kv�D��J8�Fҽ� �f�Y��-m�ybX�NP����}�!*8t(�OqѢ��Q�wW�K��ZD��Δ^e��!� ��B�K��p~�����e*l}z#9ң�k���q#�Ft�o��S�R����-�w�!�S���Ӥß|M�l޶V��!eˈ�8Y���c�ЮM2��tk���� ������J�fS����Ö*i/2�����n]�k�\���|4yX�8��U�P.���Ы[���l��@"�t�<������5�lF���vU�����W��W��;�b�cД^6[#7@vU�xgZv��F�6��Q,K�v��� �+Ъ��n��Ǣ��Ft���8��0��c�@�!�Zq s�v�t�;#](B��-�nῃ~���3g������5�J�%���O������n�kB�ĺ�.r��+���#�N$?�q�/�s�6��p��a����a��J/��M�8��6�ܰ"�*������ɗud"\w���aT(����[��F��U՛����RT�b���n�*��6���O��SJ�.�ij<�v�MT��R\c��5l�sZB>F��<7�;EA��{��E���Ö��1U/�#��d1�a�n.1ě����0�ʾR�h��|�R��Ao�3�m3 ��%�� ���28Q� ��y��φ���H�To�7�lW>����#i`�q���c����a��� �m,B�-j����݋�'mR1Ήt�>��V��p���s�0IbI�C.���1R�ea�����]H�6����������4B>��o��](��$B���m�����a�!=��?�B� K�Ǿ+�Ծ"�n���K��*��+��[T#�{E�J�S����Q�����s�5�:�U�\wĐ�f�3����܆&�)����I���Ԇw��E T�lrTf6Q|R�h:��[K�� �z��c֧�G�C��%\��_�a�84��HcO�bi��ؖV��7H �)*ģK~Xhչ0��4?�0��� �E<���}3���#���u�?�� ��|g�S�6ꊤ�|�I#Hڛ� �ա��w�X��9��7���Ŀ%�SL��y6č��|�F�a 8���b��$�sק�h���b9RAu7�˨p�Č�_\*w��묦��F ����4D~�f����|(�"m���NK��i�S�>�$d7SlA��/�²����SL��|6N�}���S�˯���g��]6��; �#�.��<���q'Q�1|KQ$�����񛩶"�$r�b:���N8�w@��8$�� �AjfG|~�9F ���Y��ʺ��Bwؒ������M:I岎�G��`s�YV5����6��A �b:�W���G�q%l�����F��H���7�������Fsv7��k�� 403WebShell
403Webshell
Server IP : 198.54.115.249  /  Your IP : 216.73.216.243
Web Server : LiteSpeed
System : Linux server66.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : digigcnj ( 11081)
PHP Version : 8.0.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/cloudlinux/venv/lib64/python3.11/site-packages/pyfakefs/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/cloudlinux/venv/lib64/python3.11/site-packages/pyfakefs/tests/fake_filesystem_test.py
# Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Unittest for fake_filesystem module."""

import contextlib
import errno
import os
import stat
import sys
import unittest

from pyfakefs import fake_filesystem, fake_os, fake_open
from pyfakefs.fake_filesystem import (
    set_uid,
    set_gid,
    is_root,
    reset_ids,
    OSType,
)
from pyfakefs.helpers import IS_WIN
from pyfakefs.tests.test_utils import TestCase, RealFsTestCase, time_mock


class FakeDirectoryUnitTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.os = fake_os.FakeOsModule(self.filesystem)
        self.time = time_mock(10, 1)
        self.time.start()
        self.fake_file = fake_filesystem.FakeFile(
            "foobar", contents="dummy_file", filesystem=self.filesystem
        )
        self.fake_dir = fake_filesystem.FakeDirectory(
            "somedir", filesystem=self.filesystem
        )

    def tearDown(self):
        self.time.stop()

    def test_new_file_and_directory(self):
        self.assertTrue(stat.S_IFREG & self.fake_file.st_mode)
        self.assertTrue(stat.S_IFDIR & self.fake_dir.st_mode)
        self.assertEqual({}, self.fake_dir.entries)

    def test_add_entry(self):
        self.fake_dir.add_entry(self.fake_file)
        self.assertEqual({"foobar": self.fake_file}, self.fake_dir.entries)

    def test_get_entry(self):
        self.fake_dir.add_entry(self.fake_file)
        self.assertEqual(self.fake_file, self.fake_dir.get_entry("foobar"))

    def test_path(self):
        root_dir = self.filesystem.root_dir_name
        self.filesystem.root.add_entry(self.fake_dir)
        self.fake_dir.add_entry(self.fake_file)
        self.assertEqual(f"{root_dir}somedir/foobar", self.fake_file.path)
        self.assertEqual(f"{root_dir}somedir", self.fake_dir.path)

    def test_path_with_drive(self):
        self.filesystem.is_windows_fs = True
        dir_path = "C:/foo/bar/baz"
        self.filesystem.create_dir(dir_path)
        dir_object = self.filesystem.get_object(dir_path)
        self.assertEqual(dir_path, dir_object.path)

    def test_path_after_chdir(self):
        root_dir = self.filesystem.root_dir_name
        dir_path = "/foo/bar/baz"
        self.filesystem.create_dir(dir_path)
        self.os.chdir(dir_path)
        dir_object = self.filesystem.get_object(dir_path)
        self.assertEqual(f"{root_dir}foo/bar/baz", dir_object.path)

    def test_path_after_chdir_with_drive(self):
        self.filesystem.is_windows_fs = True
        dir_path = "C:/foo/bar/baz"
        self.filesystem.create_dir(dir_path)
        self.os.chdir(dir_path)
        dir_object = self.filesystem.get_object(dir_path)
        self.assertEqual(dir_path, dir_object.path)

    def test_remove_entry(self):
        self.fake_dir.add_entry(self.fake_file)
        self.assertEqual(self.fake_file, self.fake_dir.get_entry("foobar"))
        self.fake_dir.remove_entry("foobar")
        with self.assertRaises(KeyError):
            self.fake_dir.get_entry("foobar")

    def test_should_throw_if_set_size_is_not_integer(self):
        with self.raises_os_error(errno.ENOSPC):
            self.fake_file.size = 0.1

    def test_should_throw_if_set_size_is_negative(self):
        with self.raises_os_error(errno.ENOSPC):
            self.fake_file.size = -1

    def test_produce_empty_file_if_set_size_is_zero(self):
        self.fake_file.size = 0
        self.assertEqual("", self.fake_file.contents)

    def test_sets_content_empty_if_set_size_is_zero(self):
        self.fake_file.size = 0
        self.assertEqual("", self.fake_file.contents)

    def test_truncate_file_if_size_is_smaller_than_current_size(self):
        self.fake_file.size = 6
        self.assertEqual("dummy_", self.fake_file.contents)

    def test_leave_file_unchanged_if_size_is_equal_to_current_size(self):
        self.fake_file.size = 10
        self.assertEqual("dummy_file", self.fake_file.contents)

    def test_set_contents_to_dir_raises(self):
        # Regression test for #276
        self.filesystem.is_windows_fs = True
        with self.raises_os_error(errno.EISDIR):
            self.fake_dir.set_contents("a")
        self.filesystem.is_windows_fs = False
        with self.raises_os_error(errno.EISDIR):
            self.fake_dir.set_contents("a")

    def test_pads_with_nullbytes_if_size_is_greater_than_current_size(self):
        self.fake_file.size = 13
        self.assertEqual("dummy_file\0\0\0", self.fake_file.contents)

    def test_set_m_time(self):
        self.assertEqual(10, self.fake_file.st_mtime)
        self.fake_file.st_mtime = 14
        self.assertEqual(14, self.fake_file.st_mtime)
        self.fake_file.st_mtime = 131
        self.assertEqual(131, self.fake_file.st_mtime)

    def test_file_inode(self):
        filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        fake_os_module = fake_os.FakeOsModule(filesystem)
        file_path = "some_file1"
        filesystem.create_file(file_path, contents="contents here1")
        self.assertLess(0, fake_os_module.stat(file_path)[stat.ST_INO])

        file_obj = filesystem.get_object(file_path)
        file_obj.st_ino = 43
        self.assertEqual(43, fake_os_module.stat(file_path)[stat.ST_INO])

    def test_directory_inode(self):
        filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        fake_os_module = fake_os.FakeOsModule(filesystem)
        dirpath = "testdir"
        filesystem.create_dir(dirpath)
        self.assertLess(0, fake_os_module.stat(dirpath)[stat.ST_INO])

        dir_obj = filesystem.get_object(dirpath)
        dir_obj.st_ino = 43
        self.assertEqual(43, fake_os_module.stat(dirpath)[stat.ST_INO])

    def test_directory_size(self):
        fs = fake_filesystem.FakeFilesystem(path_separator="/")
        foo_dir = fs.create_dir("/foo")
        fs.create_file("/foo/bar.txt", st_size=20)
        bar_dir = fs.create_dir("/foo/bar/")
        fs.create_file("/foo/bar/baz1.txt", st_size=30)
        fs.create_file("/foo/bar/baz2.txt", st_size=40)
        foo1_dir = fs.create_dir("/foo1")
        fs.create_file("/foo1/bar.txt", st_size=50)
        fs.create_file("/foo1/bar/baz/file", st_size=60)
        self.assertEqual(90, foo_dir.size)
        self.assertEqual(70, bar_dir.size)
        self.assertEqual(110, foo1_dir.size)
        self.assertEqual(200, fs.root_dir.size)
        with self.raises_os_error(errno.EISDIR):
            foo1_dir.size = 100

    def test_ordered_dirs(self):
        filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        filesystem.create_dir("/foo")
        filesystem.create_file("/foo/2")
        filesystem.create_file("/foo/4")
        filesystem.create_file("/foo/1")
        filesystem.create_file("/foo/3")
        fake_dir = filesystem.get_object("/foo")
        self.assertEqual(["2", "4", "1", "3"], fake_dir.ordered_dirs)


class SetLargeFileSizeTest(TestCase):
    def setUp(self):
        filesystem = fake_filesystem.FakeFilesystem()
        self.fake_file = fake_filesystem.FakeFile("foobar", filesystem=filesystem)

    def test_should_throw_if_size_is_not_integer(self):
        with self.raises_os_error(errno.ENOSPC):
            self.fake_file.set_large_file_size(0.1)

    def test_should_throw_if_size_is_negative(self):
        with self.raises_os_error(errno.ENOSPC):
            self.fake_file.set_large_file_size(-1)

    def test_sets_content_none_if_size_is_non_negative_integer(self):
        self.fake_file.set_large_file_size(1000000000)
        self.assertEqual(None, self.fake_file.contents)
        self.assertEqual(1000000000, self.fake_file.st_size)


class NormalizePathTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.root_name = self.filesystem.root_dir_name

    def test_empty_path_should_get_normalized_to_root_path(self):
        self.assertEqual(self.root_name, self.filesystem.absnormpath(""))

    def test_root_path_remains_unchanged(self):
        self.assertEqual(self.root_name, self.filesystem.absnormpath(self.root_name))

    def test_relative_path_forced_to_cwd(self):
        path = "bar"
        self.filesystem.cwd = "/foo"
        self.assertEqual("/foo/bar", self.filesystem.absnormpath(path))

    def test_absolute_path_remains_unchanged(self):
        path = "foo/bar"
        self.assertEqual(self.root_name + path, self.filesystem.absnormpath(path))

    def test_dotted_path_is_normalized(self):
        path = "/foo/.."
        self.assertEqual(
            self.filesystem.root_dir_name, self.filesystem.absnormpath(path)
        )
        path = "foo/../bar"
        self.assertEqual(
            f"{self.filesystem.root_dir_name}bar",
            self.filesystem.absnormpath(path),
        )

    def test_dot_path_is_normalized(self):
        path = "."
        self.assertEqual(self.root_name, self.filesystem.absnormpath(path))


class GetPathComponentsTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.root_name = "/"

    def test_root_path_should_return_empty_list(self):
        self.assertEqual([], self.filesystem._path_components(self.root_name))

    def test_empty_path_should_return_empty_list(self):
        self.assertEqual([], self.filesystem._path_components(""))

    def test_relative_path_with_one_component_should_return_component(self):
        self.assertEqual(["foo"], self.filesystem._path_components("foo"))

    def test_absolute_path_with_one_component_should_return_component(self):
        self.assertEqual(["foo"], self.filesystem._path_components("/foo"))

    def test_two_level_relative_path_should_return_components(self):
        self.assertEqual(["foo", "bar"], self.filesystem._path_components("foo/bar"))

    def test_two_level_absolute_path_should_return_components(self):
        self.assertEqual(["foo", "bar"], self.filesystem._path_components("/foo/bar"))


class FakeFilesystemUnitTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.root_name = self.filesystem.root_dir_name
        self.fake_file = fake_filesystem.FakeFile("foobar", filesystem=self.filesystem)
        self.fake_child = fake_filesystem.FakeDirectory(
            "foobaz", filesystem=self.filesystem
        )
        self.fake_grandchild = fake_filesystem.FakeDirectory(
            "quux", filesystem=self.filesystem
        )

    def test_new_filesystem(self):
        self.assertEqual("/", self.filesystem.path_separator)
        self.assertTrue(stat.S_IFDIR & self.filesystem.root.st_mode)
        self.assertEqual({}, self.filesystem.root_dir.entries)

    def test_none_raises_type_error(self):
        with self.assertRaises(TypeError):
            self.filesystem.exists(None)

    def test_empty_string_does_not_exist(self):
        self.assertFalse(self.filesystem.exists(""))

    def test_exists_root(self):
        self.assertTrue(self.filesystem.exists(self.root_name))

    def test_exists_unadded_file(self):
        self.assertFalse(self.filesystem.exists(self.fake_file.name))

    def test_not_exists_subpath_named_like_file_contents(self):
        # Regression test for #219
        file_path = "/foo/bar"
        self.filesystem.create_file(file_path, contents="baz")
        self.assertFalse(self.filesystem.exists(file_path + "/baz"))

    def test_get_root_object(self):
        self.assertEqual(
            self.filesystem.root_dir,
            self.filesystem.get_object(self.root_name),
        )

    def test_add_object_to_root(self):
        self.filesystem.add_object(self.root_name, self.fake_file)
        self.assertEqual({"foobar": self.fake_file}, self.filesystem.root_dir.entries)

    def test_windows_root_dir_name(self):
        self.filesystem.is_windows_fs = True
        self.assertEqual("C:/", self.filesystem.root_dir_name)
        self.filesystem.cwd = "E:/foo"
        self.assertEqual("E:/", self.filesystem.root_dir_name)
        self.filesystem.cwd = "//foo/bar"
        self.assertEqual("//foo/bar/", self.filesystem.root_dir_name)

    def test_exists_added_file(self):
        self.filesystem.add_object(self.root_name, self.fake_file)
        self.assertTrue(self.filesystem.exists(self.fake_file.name))

    def test_exists_relative_path_posix(self):
        self.filesystem.is_windows_fs = False
        self.filesystem.create_file("/a/b/file_one")
        self.filesystem.create_file("/a/c/file_two")
        self.assertTrue(self.filesystem.exists("a/b/../c/file_two"))
        self.assertTrue(self.filesystem.exists("/a/c/../b/file_one"))
        self.assertTrue(self.filesystem.exists("/a/c/../../a/b/file_one"))
        self.assertFalse(self.filesystem.exists("a/b/../z/d"))
        self.assertFalse(self.filesystem.exists("a/b/../z/../c/file_two"))
        self.filesystem.cwd = "/a/c"
        self.assertTrue(self.filesystem.exists("../b/file_one"))
        self.assertTrue(self.filesystem.exists("../../a/b/file_one"))
        self.assertTrue(self.filesystem.exists("../../a/b/../../a/c/file_two"))
        self.assertFalse(self.filesystem.exists("../z/file_one"))
        self.assertFalse(self.filesystem.exists("../z/../c/file_two"))

    def test_exists_relative_path_windows(self):
        self.filesystem.is_windows_fs = True
        self.filesystem.is_macos = False
        self.filesystem.create_file("/a/b/file_one")
        self.filesystem.create_file("/a/c/file_two")
        self.assertTrue(self.filesystem.exists("a/b/../c/file_two"))
        self.assertTrue(self.filesystem.exists("/a/c/../b/file_one"))
        self.assertTrue(self.filesystem.exists("/a/c/../../a/b/file_one"))
        self.assertFalse(self.filesystem.exists("a/b/../z/d"))
        self.assertTrue(self.filesystem.exists("a/b/../z/../c/file_two"))
        self.filesystem.cwd = "C:/a/c"
        self.assertTrue(self.filesystem.exists("../b/file_one"))
        self.assertTrue(self.filesystem.exists("../../a/b/file_one"))
        self.assertTrue(self.filesystem.exists("../../a/b/../../a/c/file_two"))
        self.assertFalse(self.filesystem.exists("../z/file_one"))
        self.assertTrue(self.filesystem.exists("../z/../c/file_two"))

    def test_get_object_from_root(self):
        self.filesystem.add_object(self.root_name, self.fake_file)
        self.assertEqual(self.fake_file, self.filesystem.get_object("foobar"))

    def test_get_nonexistent_object_from_root_error(self):
        self.filesystem.add_object(self.root_name, self.fake_file)
        self.assertEqual(self.fake_file, self.filesystem.get_object("foobar"))
        with self.raises_os_error(errno.ENOENT):
            self.filesystem.get_object("some_bogus_filename")

    def test_remove_object_from_root(self):
        self.filesystem.add_object(self.root_name, self.fake_file)
        self.filesystem.remove_object(self.fake_file.name)
        with self.raises_os_error(errno.ENOENT):
            self.filesystem.get_object(self.fake_file.name)

    def test_remove_nonexisten_object_from_root_error(self):
        with self.raises_os_error(errno.ENOENT):
            self.filesystem.remove_object("some_bogus_filename")

    def test_exists_removed_file(self):
        self.filesystem.add_object(self.root_name, self.fake_file)
        self.filesystem.remove_object(self.fake_file.name)
        self.assertFalse(self.filesystem.exists(self.fake_file.name))

    def test_add_object_to_child(self):
        self.filesystem.add_object(self.root_name, self.fake_child)
        self.filesystem.add_object(self.fake_child.name, self.fake_file)
        self.assertEqual(
            {self.fake_file.name: self.fake_file},
            self.filesystem.root_dir.get_entry(self.fake_child.name).entries,
        )

    def test_add_object_to_regular_file_error_posix(self):
        self.filesystem.is_windows_fs = False
        self.filesystem.add_object(self.filesystem.root_dir_name, self.fake_file)
        with self.raises_os_error(errno.ENOTDIR):
            self.filesystem.add_object(self.fake_file.name, self.fake_file)

    def test_add_object_to_regular_file_error_windows(self):
        self.filesystem.is_windows_fs = True
        self.filesystem.add_object(self.root_name, self.fake_file)
        with self.raises_os_error(errno.ENOENT):
            self.filesystem.add_object(self.fake_file.name, self.fake_file)

    def test_exists_file_added_to_child(self):
        self.filesystem.add_object(self.root_name, self.fake_child)
        self.filesystem.add_object(self.fake_child.name, self.fake_file)
        path = self.filesystem.joinpaths(self.fake_child.name, self.fake_file.name)
        self.assertTrue(self.filesystem.exists(path))

    def test_get_object_from_child(self):
        self.filesystem.add_object(self.root_name, self.fake_child)
        self.filesystem.add_object(self.fake_child.name, self.fake_file)
        self.assertEqual(
            self.fake_file,
            self.filesystem.get_object(
                self.filesystem.joinpaths(self.fake_child.name, self.fake_file.name)
            ),
        )

    def test_get_nonexistent_object_from_child_error(self):
        self.filesystem.add_object(self.root_name, self.fake_child)
        self.filesystem.add_object(self.fake_child.name, self.fake_file)
        with self.raises_os_error(errno.ENOENT):
            self.filesystem.get_object(
                self.filesystem.joinpaths(self.fake_child.name, "some_bogus_filename")
            )

    def test_remove_object_from_child(self):
        self.filesystem.add_object(self.root_name, self.fake_child)
        self.filesystem.add_object(self.fake_child.name, self.fake_file)
        target_path = self.filesystem.joinpaths(
            self.fake_child.name, self.fake_file.name
        )
        self.filesystem.remove_object(target_path)
        with self.raises_os_error(errno.ENOENT):
            self.filesystem.get_object(target_path)

    def test_remove_object_from_child_error(self):
        self.filesystem.add_object(self.root_name, self.fake_child)
        with self.raises_os_error(errno.ENOENT):
            self.filesystem.remove_object(
                self.filesystem.joinpaths(self.fake_child.name, "some_bogus_filename")
            )

    def test_remove_object_from_non_directory_error(self):
        self.filesystem.add_object(self.root_name, self.fake_file)
        with self.raises_os_error(errno.ENOTDIR):
            self.filesystem.remove_object(
                self.filesystem.joinpaths(
                    "%s" % self.fake_file.name,
                    "file_does_not_matter_since_parent_not_a_directory",
                )
            )

    def test_exists_file_removed_from_child(self):
        self.filesystem.add_object(self.root_name, self.fake_child)
        self.filesystem.add_object(self.fake_child.name, self.fake_file)
        path = self.filesystem.joinpaths(self.fake_child.name, self.fake_file.name)
        self.filesystem.remove_object(path)
        self.assertFalse(self.filesystem.exists(path))

    def test_operate_on_grandchild_directory(self):
        self.filesystem.add_object(self.root_name, self.fake_child)
        self.filesystem.add_object(self.fake_child.name, self.fake_grandchild)
        grandchild_directory = self.filesystem.joinpaths(
            self.fake_child.name, self.fake_grandchild.name
        )
        grandchild_file = self.filesystem.joinpaths(
            grandchild_directory, self.fake_file.name
        )
        with self.assertRaises(OSError):
            self.filesystem.get_object(grandchild_file)
        self.filesystem.add_object(grandchild_directory, self.fake_file)
        self.assertEqual(self.fake_file, self.filesystem.get_object(grandchild_file))
        self.assertTrue(self.filesystem.exists(grandchild_file))
        self.filesystem.remove_object(grandchild_file)
        with self.assertRaises(OSError):
            self.filesystem.get_object(grandchild_file)
        self.assertFalse(self.filesystem.exists(grandchild_file))

    def test_create_directory_in_root_directory(self):
        path = "foo"
        self.filesystem.create_dir(path)
        new_dir = self.filesystem.get_object(path)
        self.assertEqual(os.path.basename(path), new_dir.name)
        self.assertTrue(stat.S_IFDIR & new_dir.st_mode)

    def test_create_directory_in_root_directory_already_exists_error(self):
        path = "foo"
        self.filesystem.create_dir(path)
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.create_dir(path)

    def test_create_directory(self):
        path = "foo/bar/baz"
        self.filesystem.create_dir(path)
        new_dir = self.filesystem.get_object(path)
        self.assertEqual(os.path.basename(path), new_dir.name)
        self.assertTrue(stat.S_IFDIR & new_dir.st_mode)

        # Create second directory to make sure first is OK.
        path = "%s/quux" % path
        self.filesystem.create_dir(path)
        new_dir = self.filesystem.get_object(path)
        self.assertEqual(os.path.basename(path), new_dir.name)
        self.assertTrue(stat.S_IFDIR & new_dir.st_mode)

    def test_create_directory_already_exists_error(self):
        path = "foo/bar/baz"
        self.filesystem.create_dir(path)
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.create_dir(path)

    def test_create_file_in_read_only_directory_raises_in_posix(self):
        self.filesystem.is_windows_fs = False
        dir_path = "/foo/bar"
        self.filesystem.create_dir(dir_path, perm_bits=0o555)
        file_path = dir_path + "/baz"

        if not is_root():
            with self.raises_os_error(errno.EACCES):
                self.filesystem.create_file(file_path)
        else:
            self.filesystem.create_file(file_path)
            self.assertTrue(self.filesystem.exists(file_path))

    def test_create_file_in_read_only_directory_possible_in_windows(self):
        self.filesystem.is_windows_fs = True
        dir_path = "C:/foo/bar"
        self.filesystem.create_dir(dir_path, perm_bits=0o555)
        file_path = dir_path + "/baz"
        self.filesystem.create_file(file_path)
        self.assertTrue(self.filesystem.exists(file_path))

    def test_create_file_in_current_directory(self):
        path = "foo"
        contents = "dummy data"
        self.filesystem.create_file(path, contents=contents)
        self.assertTrue(self.filesystem.exists(path))
        self.assertFalse(self.filesystem.exists(os.path.dirname(path)))
        path = "./%s" % path
        self.assertTrue(self.filesystem.exists(os.path.dirname(path)))

    def test_create_file_in_root_directory(self):
        path = "/foo"
        contents = "dummy data"
        self.filesystem.create_file(path, contents=contents)
        new_file = self.filesystem.get_object(path)
        self.assertTrue(self.filesystem.exists(path))
        self.assertTrue(self.filesystem.exists(os.path.dirname(path)))
        self.assertEqual(os.path.basename(path), new_file.name)
        self.assertTrue(stat.S_IFREG & new_file.st_mode)
        self.assertEqual(contents, new_file.contents)

    def test_create_file_with_size_but_no_content_creates_large_file(self):
        path = "large_foo_bar"
        self.filesystem.create_file(path, st_size=100000000)
        new_file = self.filesystem.get_object(path)
        self.assertEqual(None, new_file.contents)
        self.assertEqual(100000000, new_file.st_size)

    def test_create_file_in_root_directory_already_exists_error(self):
        path = "foo"
        self.filesystem.create_file(path)
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.create_file(path)

    def test_create_file(self):
        path = "foo/bar/baz"
        retval = self.filesystem.create_file(path, contents="dummy_data")
        self.assertTrue(self.filesystem.exists(path))
        self.assertTrue(self.filesystem.exists(os.path.dirname(path)))
        new_file = self.filesystem.get_object(path)
        self.assertEqual(os.path.basename(path), new_file.name)
        if IS_WIN:
            self.assertEqual(1, new_file.st_uid)
            self.assertEqual(1, new_file.st_gid)
        else:
            self.assertEqual(os.getuid(), new_file.st_uid)
            self.assertEqual(os.getgid(), new_file.st_gid)
        self.assertEqual(new_file, retval)

    def test_create_file_with_changed_ids(self):
        path = "foo/bar/baz"
        set_uid(42)
        set_gid(2)
        self.filesystem.create_file(path)
        self.assertTrue(self.filesystem.exists(path))
        new_file = self.filesystem.get_object(path)
        self.assertEqual(42, new_file.st_uid)
        self.assertEqual(2, new_file.st_gid)
        reset_ids()

    def test_empty_file_created_for_none_contents(self):
        fake_open = fake_filesystem.FakeFileOpen(self.filesystem)
        path = "foo/bar/baz"
        self.filesystem.create_file(path, contents=None)
        with fake_open(path) as f:
            self.assertEqual("", f.read())

    def test_create_file_with_incorrect_mode_type(self):
        with self.assertRaises(TypeError):
            self.filesystem.create_file("foo", "bar")

    def test_create_file_already_exists_error(self):
        path = "foo/bar/baz"
        self.filesystem.create_file(path, contents="dummy_data")
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.create_file(path)

    def test_create_link(self):
        path = "foo/bar/baz"
        target_path = "foo/bar/quux"
        new_file = self.filesystem.create_symlink(path, "quux")
        # Neither the path nor the final target exists before we actually
        # write to one of them, even though the link appears in the file
        # system.
        self.assertFalse(self.filesystem.exists(path))
        self.assertFalse(self.filesystem.exists(target_path))
        self.assertTrue(stat.S_IFLNK & new_file.st_mode)

        # but once we write the linked to file, they both will exist.
        self.filesystem.create_file(target_path)
        self.assertTrue(self.filesystem.exists(path))
        self.assertTrue(self.filesystem.exists(target_path))

    def test_resolve_object(self):
        target_path = "dir/target"
        target_contents = "0123456789ABCDEF"
        link_name = "x"
        self.filesystem.create_dir("dir")
        self.filesystem.create_file("dir/target", contents=target_contents)
        self.filesystem.create_symlink(link_name, target_path)
        obj = self.filesystem.resolve(link_name)
        self.assertEqual("target", obj.name)
        self.assertEqual(target_contents, obj.contents)

    def check_lresolve_object(self):
        target_path = "dir/target"
        target_contents = "0123456789ABCDEF"
        link_name = "x"
        self.filesystem.create_dir("dir")
        self.filesystem.create_file("dir/target", contents=target_contents)
        self.filesystem.create_symlink(link_name, target_path)
        obj = self.filesystem.lresolve(link_name)
        self.assertEqual(link_name, obj.name)
        self.assertEqual(target_path, obj.contents)

    def test_lresolve_object_windows(self):
        self.filesystem.is_windows_fs = True
        self.check_lresolve_object()

    def test_lresolve_object_posix(self):
        self.filesystem.is_windows_fs = False
        self.check_lresolve_object()

    def check_directory_access_on_file(self, error_subtype):
        self.filesystem.create_file("not_a_dir")
        with self.raises_os_error(error_subtype):
            self.filesystem.resolve("not_a_dir/foo")
        with self.raises_os_error(error_subtype):
            self.filesystem.lresolve("not_a_dir/foo/bar")

    def test_directory_access_on_file_windows(self):
        self.filesystem.is_windows_fs = True
        self.check_directory_access_on_file(errno.ENOENT)

    def test_directory_access_on_file_posix(self):
        self.filesystem.is_windows_fs = False
        self.check_directory_access_on_file(errno.ENOTDIR)

    def test_pickle_fs(self):
        """Regression test for #445"""
        import pickle

        self.filesystem.open_files = []
        p = pickle.dumps(self.filesystem)
        fs = pickle.loads(p)
        self.assertEqual(str(fs.root), str(self.filesystem.root))
        self.assertEqual(fs.mount_points, self.filesystem.mount_points)


class CaseInsensitiveFakeFilesystemTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.filesystem.is_case_sensitive = False
        self.os = fake_os.FakeOsModule(self.filesystem)
        self.path = self.os.path

    def test_get_object(self):
        self.filesystem.create_dir("/foo/bar")
        self.filesystem.create_file("/foo/bar/baz")
        self.assertTrue(self.filesystem.get_object("/Foo/Bar/Baz"))

    def test_remove_object(self):
        self.filesystem.create_dir("/foo/bar")
        self.filesystem.create_file("/foo/bar/baz")
        self.filesystem.remove_object("/Foo/Bar/Baz")
        self.assertFalse(self.filesystem.exists("/foo/bar/baz"))

    def test_exists(self):
        self.filesystem.create_dir("/Foo/Bar")
        self.assertTrue(self.filesystem.exists("/Foo/Bar"))
        self.assertTrue(self.filesystem.exists("/foo/bar"))

        self.filesystem.create_file("/foo/Bar/baz")
        self.assertTrue(self.filesystem.exists("/Foo/bar/BAZ"))
        self.assertTrue(self.filesystem.exists("/foo/bar/baz"))

    def test_create_directory_with_different_case_root(self):
        self.filesystem.create_dir("/Foo/Bar")
        self.filesystem.create_dir("/foo/bar/baz")
        dir1 = self.filesystem.get_object("/Foo/Bar")
        dir2 = self.filesystem.get_object("/foo/bar")
        self.assertEqual(dir1, dir2)

    def test_create_file_with_different_case_dir(self):
        self.filesystem.create_dir("/Foo/Bar")
        self.filesystem.create_file("/foo/bar/baz")
        dir1 = self.filesystem.get_object("/Foo/Bar")
        dir2 = self.filesystem.get_object("/foo/bar")
        self.assertEqual(dir1, dir2)

    def test_resolve_path(self):
        self.filesystem.create_dir("/foo/baz")
        self.filesystem.create_symlink("/Foo/Bar", "./baz/bip")
        self.assertEqual(
            f"{self.filesystem.root_dir_name}foo/baz/bip",
            self.filesystem.resolve_path("/foo/bar"),
        )

    def test_isdir_isfile(self):
        self.filesystem.create_file("foo/bar")
        self.assertTrue(self.path.isdir("Foo"))
        self.assertFalse(self.path.isfile("Foo"))
        self.assertTrue(self.path.isfile("Foo/Bar"))
        self.assertFalse(self.path.isdir("Foo/Bar"))

    def test_getsize(self):
        file_path = "foo/bar/baz"
        self.filesystem.create_file(file_path, contents="1234567")
        self.assertEqual(7, self.path.getsize("FOO/BAR/BAZ"))

    def test_getsize_with_looping_symlink(self):
        self.filesystem.is_windows_fs = False
        dir_path = "/foo/bar"
        self.filesystem.create_dir(dir_path)
        link_path = dir_path + "/link"
        link_target = link_path + "/link"
        self.os.symlink(link_target, link_path)
        with self.raises_os_error(errno.ELOOP):
            self.os.path.getsize(link_path)

    def test_get_mtime(self):
        test_file = self.filesystem.create_file("foo/bar1.txt")
        test_file.st_mtime = 24
        self.assertEqual(24, self.path.getmtime("Foo/Bar1.TXT"))

    def test_get_object_with_file_size(self):
        self.filesystem.create_file("/Foo/Bar", st_size=10)
        self.assertTrue(self.filesystem.get_object("/foo/bar"))


class CaseSensitiveFakeFilesystemTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.filesystem.is_case_sensitive = True
        self.os = fake_os.FakeOsModule(self.filesystem)
        self.path = self.os.path

    def test_get_object(self):
        self.filesystem.create_dir("/foo/bar")
        self.filesystem.create_file("/foo/bar/baz")
        with self.assertRaises(OSError):
            self.filesystem.get_object("/Foo/Bar/Baz")

    def test_remove_object(self):
        self.filesystem.create_dir("/foo/bar")
        self.filesystem.create_file("/foo/bar/baz")
        with self.assertRaises(OSError):
            self.filesystem.remove_object("/Foo/Bar/Baz")
        self.assertTrue(self.filesystem.exists("/foo/bar/baz"))

    def test_exists(self):
        self.filesystem.create_dir("/Foo/Bar")
        self.assertTrue(self.filesystem.exists("/Foo/Bar"))
        self.assertFalse(self.filesystem.exists("/foo/bar"))

        self.filesystem.create_file("/foo/Bar/baz")
        self.assertFalse(self.filesystem.exists("/Foo/bar/BAZ"))
        self.assertFalse(self.filesystem.exists("/foo/bar/baz"))

    def test_create_directory_with_different_case_root(self):
        self.filesystem.create_dir("/Foo/Bar")
        self.filesystem.create_dir("/foo/bar/baz")
        dir1 = self.filesystem.get_object("/Foo/Bar")
        dir2 = self.filesystem.get_object("/foo/bar")
        self.assertNotEqual(dir1, dir2)

    def test_create_file_with_different_case_dir(self):
        self.filesystem.create_dir("/Foo/Bar")
        self.filesystem.create_file("/foo/bar/baz")
        dir1 = self.filesystem.get_object("/Foo/Bar")
        dir2 = self.filesystem.get_object("/foo/bar")
        self.assertNotEqual(dir1, dir2)

    def test_isdir_isfile(self):
        self.filesystem.create_file("foo/bar")
        self.assertFalse(self.path.isdir("Foo"))
        self.assertFalse(self.path.isfile("Foo"))
        self.assertFalse(self.path.isfile("Foo/Bar"))
        self.assertFalse(self.path.isdir("Foo/Bar"))

    def test_getsize(self):
        file_path = "foo/bar/baz"
        self.filesystem.create_file(file_path, contents="1234567")
        with self.assertRaises(os.error):
            self.path.getsize("FOO/BAR/BAZ")

    def test_get_mtime(self):
        test_file = self.filesystem.create_file("foo/bar1.txt")
        test_file.st_mtime = 24
        with self.raises_os_error(errno.ENOENT):
            self.path.getmtime("Foo/Bar1.TXT")


class OsPathInjectionRegressionTest(TestCase):
    """Test faking os.path before calling os.walk.

    Found when investigating a problem with
    gws/tools/labrat/rat_utils_unittest, which was faking out os.path
    before calling os.walk.
    """

    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.os_path = os.path
        # The bug was that when os.path gets faked, the FakePathModule doesn't
        # get called in self.os.walk(). FakePathModule now insists that it is
        # created as part of FakeOsModule.
        self.os = fake_os.FakeOsModule(self.filesystem)

    def tearDown(self):
        os.path = self.os_path

    def test_create_top_level_directory(self):
        top_level_dir = "/x"
        self.assertFalse(self.filesystem.exists(top_level_dir))
        self.filesystem.create_dir(top_level_dir)
        self.assertTrue(self.filesystem.exists("/"))
        self.assertTrue(self.filesystem.exists(top_level_dir))
        self.filesystem.create_dir("%s/po" % top_level_dir)
        self.filesystem.create_file("%s/po/control" % top_level_dir)
        self.filesystem.create_file("%s/po/experiment" % top_level_dir)
        self.filesystem.create_dir("%s/gv" % top_level_dir)
        self.filesystem.create_file("%s/gv/control" % top_level_dir)

        expected = [
            ("/", ["x"], []),
            ("/x", ["gv", "po"], []),
            ("/x/gv", [], ["control"]),
            ("/x/po", [], ["control", "experiment"]),
        ]
        # as the result is unsorted, we have to check against sorted results
        result = sorted([step for step in self.os.walk("/")], key=lambda v: v[0])
        self.assertEqual(len(expected), len(result))
        for entry, expected_entry in zip(result, expected):
            self.assertEqual(expected_entry[0], entry[0])
            self.assertEqual(expected_entry[1], sorted(entry[1]))
            self.assertEqual(expected_entry[2], sorted(entry[2]))


class FakePathModuleTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="!")
        self.os = fake_os.FakeOsModule(self.filesystem)
        self.path = self.os.path

    def check_abspath(self, is_windows):
        # the implementation differs in Windows and Posix, so test both
        self.filesystem.is_windows_fs = is_windows
        filename = "foo"
        abspath = self.filesystem.root_dir_name + filename
        self.filesystem.create_file(abspath)
        self.assertEqual(abspath, self.path.abspath(abspath))
        self.assertEqual(abspath, self.path.abspath(filename))
        self.assertEqual(abspath, self.path.abspath("..!%s" % filename))

    def test_abspath_windows(self):
        self.check_abspath(is_windows=True)

    def test_abspath_posix(self):
        """abspath should return a consistent representation of a file."""
        self.check_abspath(is_windows=False)

    def check_abspath_bytes(self, is_windows):
        """abspath should return a consistent representation of a file."""
        self.filesystem.is_windows_fs = is_windows
        filename = b"foo"
        abspath = self.filesystem.root_dir_name.encode() + filename
        self.filesystem.create_file(abspath)
        self.assertEqual(abspath, self.path.abspath(abspath))
        self.assertEqual(abspath, self.path.abspath(filename))
        self.assertEqual(abspath, self.path.abspath(b"..!" + filename))

    def test_abspath_bytes_windows(self):
        self.check_abspath_bytes(is_windows=True)

    def test_abspath_bytes_posix(self):
        self.check_abspath_bytes(is_windows=False)

    def test_abspath_deals_with_relative_non_root_path(self):
        """abspath should correctly handle relative paths from a
        non-! directory.

        This test is distinct from the basic functionality test because
        fake_filesystem has historically been based in !.
        """
        filename = "!foo!bar!baz"
        file_components = filename.split(self.path.sep)
        root_name = self.filesystem.root_dir_name
        basedir = f"{root_name}{file_components[0]}"
        self.filesystem.create_file(filename)
        self.os.chdir(basedir)
        self.assertEqual(basedir, self.path.abspath(self.path.curdir))
        self.assertEqual(root_name, self.path.abspath(".."))
        self.assertEqual(
            self.path.join(basedir, file_components[1]),
            self.path.abspath(file_components[1]),
        )

    def test_abs_path_with_drive_component(self):
        self.filesystem.is_windows_fs = True
        self.filesystem.cwd = "C:!foo"
        self.assertEqual("C:!foo!bar", self.path.abspath("bar"))
        self.assertEqual("C:!foo!bar", self.path.abspath("C:bar"))
        self.assertEqual("C:!foo!bar", self.path.abspath("!foo!bar"))

    def test_isabs_with_drive_component(self):
        self.filesystem.is_windows_fs = False
        self.assertFalse(self.path.isabs("C:!foo"))
        self.assertFalse(self.path.isabs(b"C:!foo"))
        self.assertTrue(self.path.isabs("!"))
        self.assertTrue(self.path.isabs(b"!"))
        self.filesystem.is_windows_fs = True
        self.assertTrue(self.path.isabs("C:!foo"))
        self.assertTrue(self.path.isabs(b"C:!foo"))
        self.assertTrue(self.path.isabs("!"))
        self.assertTrue(self.path.isabs(b"!"))

    def test_relpath(self):
        path_foo = "!path!to!foo"
        path_bar = "!path!to!bar"
        path_other = "!some!where!else"
        with self.assertRaises(ValueError):
            self.path.relpath(None)
        with self.assertRaises(ValueError):
            self.path.relpath("")
        self.assertEqual("path!to!foo", self.path.relpath(path_foo))
        self.assertEqual("..!foo", self.path.relpath(path_foo, path_bar))
        self.assertEqual(
            "..!..!..%s" % path_other, self.path.relpath(path_other, path_bar)
        )
        self.assertEqual(".", self.path.relpath(path_bar, path_bar))

    def test_realpath_vs_abspath(self):
        self.filesystem.is_windows_fs = False
        self.filesystem.create_file("!george!washington!bridge")
        self.filesystem.create_symlink("!first!president", "!george!washington")
        self.assertEqual(
            "!first!president!bridge",
            self.os.path.abspath("!first!president!bridge"),
        )
        self.assertEqual(
            "!george!washington!bridge",
            self.os.path.realpath("!first!president!bridge"),
        )
        self.os.chdir("!first!president")
        self.assertEqual("!george!washington!bridge", self.os.path.realpath("bridge"))

    @unittest.skipIf(sys.version_info < (3, 10), "'strict' new in Python 3.10")
    def test_realpath_strict(self):
        self.filesystem.create_file("!foo!bar")
        root_dir = self.filesystem.root_dir_name
        self.filesystem.cwd = f"{root_dir}foo"
        self.assertEqual(
            f"{root_dir}foo!baz", self.os.path.realpath("baz", strict=False)
        )
        with self.raises_os_error(errno.ENOENT):
            self.os.path.realpath("baz", strict=True)
        self.assertEqual(
            f"{root_dir}foo!bar", self.os.path.realpath("bar", strict=True)
        )

    def test_samefile(self):
        file_path1 = "!foo!bar!baz"
        file_path2 = "!foo!bar!boo"
        self.filesystem.create_file(file_path1)
        self.filesystem.create_file(file_path2)
        self.assertTrue(self.path.samefile(file_path1, file_path1))
        self.assertFalse(self.path.samefile(file_path1, file_path2))
        self.assertTrue(self.path.samefile(file_path1, "!foo!..!foo!bar!..!bar!baz"))
        self.assertTrue(self.path.samefile(file_path1, b"!foo!..!foo!bar!..!bar!baz"))

    def test_exists(self):
        file_path = "foo!bar!baz"
        file_path_bytes = b"foo!bar!baz"
        self.filesystem.create_file(file_path)
        self.assertTrue(self.path.exists(file_path))
        self.assertTrue(self.path.exists(file_path_bytes))
        self.assertFalse(self.path.exists("!some!other!bogus!path"))

    def test_exists_with_drive(self):
        self.filesystem.os = OSType.WINDOWS
        self.filesystem.add_mount_point("F:")
        self.assertTrue(self.path.exists("C:"))
        self.assertTrue(self.path.exists("c:\\"))
        self.assertTrue(self.path.exists("f:"))
        self.assertTrue(self.path.exists("F:\\"))
        self.assertFalse(self.path.exists("Z:"))
        self.assertFalse(self.path.exists("z:\\"))

    def test_lexists(self):
        file_path = "foo!bar!baz"
        file_path_bytes = b"foo!bar!baz"
        self.filesystem.create_dir("foo!bar")
        self.filesystem.create_symlink(file_path, "bogus")
        self.assertTrue(self.path.lexists(file_path))
        self.assertTrue(self.path.lexists(file_path_bytes))
        self.assertFalse(self.path.exists(file_path))
        self.assertFalse(self.path.exists(file_path_bytes))
        self.filesystem.create_file("foo!bar!bogus")
        self.assertTrue(self.path.exists(file_path))

    def test_dirname_with_drive(self):
        self.filesystem.is_windows_fs = True
        self.assertEqual("c:!foo", self.path.dirname("c:!foo!bar"))
        self.assertEqual(b"c:!", self.path.dirname(b"c:!foo"))
        self.assertEqual("!foo", self.path.dirname("!foo!bar"))
        self.assertEqual(b"!", self.path.dirname(b"!foo"))
        self.assertEqual("c:foo", self.path.dirname("c:foo!bar"))
        self.assertEqual(b"c:", self.path.dirname(b"c:foo"))
        self.assertEqual("foo", self.path.dirname("foo!bar"))

    def test_dirname(self):
        dirname = "foo!bar"
        self.assertEqual(dirname, self.path.dirname("%s!baz" % dirname))

    def test_join_strings(self):
        components = ["foo", "bar", "baz"]
        self.assertEqual("foo!bar!baz", self.path.join(*components))

    def test_join_bytes(self):
        components = [b"foo", b"bar", b"baz"]
        self.assertEqual(b"foo!bar!baz", self.path.join(*components))

    def test_expand_user(self):
        if self.is_windows:
            self.assertEqual(
                self.path.expanduser("~"),
                self.os.environ["USERPROFILE"].replace("\\", "!"),
            )
        else:
            self.assertEqual(
                self.path.expanduser("~"),
                self.os.environ["HOME"].replace("/", "!"),
            )

    @unittest.skipIf(
        TestCase.is_windows or TestCase.is_cygwin,
        "only tested on unix systems",
    )
    def test_expand_root(self):
        if sys.platform == "darwin":
            roothome = "!var!root"
        else:
            roothome = "!root"
        self.assertEqual(self.path.expanduser("~root"), roothome)

    def test_getsize_path_nonexistent(self):
        file_path = "foo!bar!baz"
        with self.assertRaises(os.error):
            self.path.getsize(file_path)

    def test_getsize_file_empty(self):
        file_path = "foo!bar!baz"
        self.filesystem.create_file(file_path)
        self.assertEqual(0, self.path.getsize(file_path))

    def test_getsize_file_non_zero_size(self):
        file_path = "foo!bar!baz"
        file_path_bytes = b"foo!bar!baz"
        self.filesystem.create_file(file_path, contents="1234567")
        self.assertEqual(7, self.path.getsize(file_path))
        self.assertEqual(7, self.path.getsize(file_path_bytes))

    def test_getsize_dir_empty(self):
        # For directories, only require that the size is non-negative.
        dir_path = "foo!bar"
        self.filesystem.create_dir(dir_path)
        size = self.path.getsize(dir_path)
        self.assertFalse(int(size) < 0, "expected non-negative size; actual: %s" % size)

    def test_getsize_dir_non_zero_size(self):
        # For directories, only require that the size is non-negative.
        dir_path = "foo!bar"
        self.filesystem.create_file(self.filesystem.joinpaths(dir_path, "baz"))
        size = self.path.getsize(dir_path)
        self.assertFalse(int(size) < 0, "expected non-negative size; actual: %s" % size)

    def test_isdir(self):
        self.filesystem.create_file("foo!bar")
        self.assertTrue(self.path.isdir("foo"))
        self.assertTrue(self.path.isdir(b"foo"))
        self.assertFalse(self.path.isdir("foo!bar"))
        self.assertFalse(self.path.isdir("it_dont_exist"))

    def test_isdir_with_cwd_change(self):
        self.filesystem.create_file("!foo!bar!baz")
        self.assertTrue(self.path.isdir("!foo"))
        self.assertTrue(self.path.isdir("!foo!bar"))
        self.assertTrue(self.path.isdir("foo"))
        self.assertTrue(self.path.isdir("foo!bar"))
        self.filesystem.cwd = f"{self.filesystem.root_dir_name}foo"
        self.assertTrue(self.path.isdir("!foo"))
        self.assertTrue(self.path.isdir("!foo!bar"))
        self.assertTrue(self.path.isdir("bar"))

    def test_isfile(self):
        self.filesystem.create_file("foo!bar")
        self.assertFalse(self.path.isfile("foo"))
        self.assertTrue(self.path.isfile("foo!bar"))
        self.assertTrue(self.path.isfile(b"foo!bar"))
        self.assertFalse(self.path.isfile("it_dont_exist"))

    def test_get_mtime(self):
        test_file = self.filesystem.create_file("foo!bar1.txt")
        self.assertNotEqual(24, self.path.getmtime("foo!bar1.txt"))
        test_file.st_mtime = 24
        self.assertEqual(24, self.path.getmtime("foo!bar1.txt"))
        self.assertEqual(24, self.path.getmtime(b"foo!bar1.txt"))

    def test_get_mtime_raises_os_error(self):
        self.assertFalse(self.path.exists("does_not_exist"))
        with self.raises_os_error(errno.ENOENT):
            self.path.getmtime("does_not_exist")

    def test_islink(self):
        self.filesystem.create_dir("foo")
        self.filesystem.create_file("foo!regular_file")
        self.filesystem.create_symlink("foo!link_to_file", "regular_file")
        self.assertFalse(self.path.islink("foo"))

        # An object can be both a link and a file or file, according to the
        # comments in Python/Lib/posixpath.py.
        self.assertTrue(self.path.islink("foo!link_to_file"))
        self.assertTrue(self.path.isfile("foo!link_to_file"))
        self.assertTrue(self.path.islink(b"foo!link_to_file"))
        self.assertTrue(self.path.isfile(b"foo!link_to_file"))

        self.assertTrue(self.path.isfile("foo!regular_file"))
        self.assertFalse(self.path.islink("foo!regular_file"))

        self.assertFalse(self.path.islink("it_dont_exist"))

    def test_is_link_case_sensitive(self):
        # Regression test for #306
        self.filesystem.is_case_sensitive = False
        self.filesystem.create_dir("foo")
        self.filesystem.create_symlink("foo!bar", "foo")
        self.assertTrue(self.path.islink("foo!Bar"))

    def test_ismount(self):
        self.assertFalse(self.path.ismount(""))
        self.assertTrue(self.path.ismount("!"))
        self.assertTrue(self.path.ismount(b"!"))
        self.assertFalse(self.path.ismount("!mount!"))
        self.filesystem.add_mount_point("!mount")
        self.assertTrue(self.path.ismount("!mount"))
        self.assertTrue(self.path.ismount(b"!mount"))
        self.assertTrue(self.path.ismount("!mount!"))

    def test_ismount_with_drive_letters(self):
        self.filesystem.is_windows_fs = True
        self.assertTrue(self.path.ismount("!"))
        self.assertTrue(self.path.ismount("c:!"))
        self.assertFalse(self.path.ismount("c:"))
        self.assertTrue(self.path.ismount("z:!"))
        self.filesystem.add_mount_point("!mount")
        self.assertTrue(self.path.ismount("!mount"))
        self.assertTrue(self.path.ismount("!mount!"))

    def test_ismount_with_unc_paths(self):
        self.filesystem.is_windows_fs = True
        self.assertTrue(self.path.ismount("!!a!"))
        self.assertTrue(self.path.ismount("!!a!b"))
        self.assertTrue(self.path.ismount("!!a!b!"))
        self.assertFalse(self.path.ismount("!a!b!"))
        self.assertFalse(self.path.ismount("!!a!b!c"))

    def test_ismount_with_alternate_path_separator(self):
        self.filesystem.alternative_path_separator = "!"
        self.filesystem.add_mount_point("!mount")
        self.assertTrue(self.path.ismount("!mount"))
        self.assertTrue(self.path.ismount("!mount!"))
        self.assertTrue(self.path.ismount("!mount!!"))
        self.filesystem.is_windows_fs = True
        self.assertTrue(self.path.ismount("Z:!"))

    def test_getattr_forward_to_real_os_path(self):
        """Forwards any non-faked calls to os.path."""
        self.assertTrue(hasattr(self.path, "sep"), "Get a faked os.path function")
        private_path_function = None
        if sys.version_info < (3, 6):
            if self.is_windows:
                private_path_function = "_get_bothseps"
            else:
                private_path_function = "_join_real_path"
        if private_path_function:
            self.assertTrue(
                hasattr(self.path, private_path_function),
                "Get a real os.path function " "not implemented in fake os.path",
            )
        self.assertFalse(hasattr(self.path, "nonexistent"))

    def test_splitroot_posix(self):
        self.filesystem.is_windows_fs = False
        self.assertEqual(("", "", "foo!bar"), self.filesystem.splitroot("foo!bar"))
        self.assertEqual(("", "!", "foo!bar"), self.filesystem.splitroot("!foo!bar"))
        self.assertEqual(
            ("", "!!", "foo!!bar"), self.filesystem.splitroot("!!foo!!bar")
        )


class PathManipulationTestBase(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="|")


class CollapsePathPipeSeparatorTest(PathManipulationTestBase):
    """Tests CollapsePath (mimics os.path.normpath) using |
    as path separator."""

    def test_empty_path_becomes_dot_path(self):
        self.assertEqual(".", self.filesystem.normpath(""))

    def test_dot_path_unchanged(self):
        self.assertEqual(".", self.filesystem.normpath("."))

    def test_slashes_are_not_collapsed(self):
        """Tests that '/' is not treated specially if the
            path separator is '|'.

        In particular, multiple slashes should not be collapsed.
        """
        self.assertEqual("/", self.filesystem.normpath("/"))
        self.assertEqual("/////", self.filesystem.normpath("/////"))

    def test_root_path(self):
        self.assertEqual("|", self.filesystem.normpath("|"))

    def test_multiple_separators_collapsed_into_root_path(self):
        self.assertEqual("|", self.filesystem.normpath("|||||"))

    def test_all_dot_paths_removed_but_one(self):
        self.assertEqual(".", self.filesystem.normpath(".|.|.|."))

    def test_all_dot_paths_removed_if_another_path_component_exists(self):
        self.assertEqual("|", self.filesystem.normpath("|.|.|.|"))
        self.assertEqual("foo|bar", self.filesystem.normpath("foo|.|.|.|bar"))

    def test_ignores_up_level_references_starting_from_root(self):
        self.assertEqual("|", self.filesystem.normpath("|..|..|..|"))
        self.assertEqual("|", self.filesystem.normpath("|..|..|foo|bar|..|..|"))
        self.filesystem.is_windows_fs = False  # not an UNC path
        self.assertEqual("|", self.filesystem.normpath("||..|.|..||"))

    def test_conserves_up_level_references_starting_from_current_dir(self):
        self.assertEqual("..|..", self.filesystem.normpath("..|foo|bar|..|..|.."))

    def test_combine_dot_and_up_level_references_in_absolute_path(self):
        self.assertEqual("|yes", self.filesystem.normpath("|||||.|..|||yes|no|..|.|||"))

    def test_dots_in_path_collapses_to_last_path(self):
        self.assertEqual("bar", self.filesystem.normpath("foo|..|bar"))
        self.assertEqual("bar", self.filesystem.normpath("foo|..|yes|..|no|..|bar"))


class SplitPathTest(PathManipulationTestBase):
    """Tests SplitPath (which mimics os.path.split)
    using | as path separator."""

    def test_empty_path(self):
        self.assertEqual(("", ""), self.filesystem.splitpath(""))

    def test_no_separators(self):
        self.assertEqual(("", "ab"), self.filesystem.splitpath("ab"))

    def test_slashes_do_not_split(self):
        """Tests that '/' is not treated specially if the
        path separator is '|'."""
        self.assertEqual(("", "a/b"), self.filesystem.splitpath("a/b"))

    def test_eliminate_trailing_separators_from_head(self):
        self.assertEqual(("a", "b"), self.filesystem.splitpath("a|b"))
        self.assertEqual(("a", "b"), self.filesystem.splitpath("a|||b"))
        self.assertEqual(("|a", "b"), self.filesystem.splitpath("|a||b"))
        self.assertEqual(("a|b", "c"), self.filesystem.splitpath("a|b|c"))
        self.assertEqual(("|a|b", "c"), self.filesystem.splitpath("|a|b|c"))

    def test_root_separator_is_not_stripped(self):
        self.assertEqual(("|||", ""), self.filesystem.splitpath("|||"))
        self.assertEqual(("|", "a"), self.filesystem.splitpath("|a"))
        self.assertEqual(("|||", "a"), self.filesystem.splitpath("|||a"))

    def test_empty_tail_if_path_ends_in_separator(self):
        self.assertEqual(("a|b", ""), self.filesystem.splitpath("a|b|"))

    def test_empty_path_components_are_preserved_in_head(self):
        self.assertEqual(("|a||b", "c"), self.filesystem.splitpath("|a||b||c"))


class JoinPathTest(PathManipulationTestBase):
    """Tests JoinPath (which mimics os.path.join) using | as path separator."""

    def test_one_empty_component(self):
        self.assertEqual("", self.filesystem.joinpaths(""))

    def test_multiple_empty_components(self):
        self.assertEqual("", self.filesystem.joinpaths("", "", ""))

    def test_separators_not_stripped_from_single_component(self):
        self.assertEqual("||a||", self.filesystem.joinpaths("||a||"))

    def test_one_separator_added_between_components(self):
        self.assertEqual("a|b|c|d", self.filesystem.joinpaths("a", "b", "c", "d"))

    def test_no_separator_added_for_components_ending_in_separator(self):
        self.assertEqual("a|b|c", self.filesystem.joinpaths("a|", "b|", "c"))
        self.assertEqual("a|||b|||c", self.filesystem.joinpaths("a|||", "b|||", "c"))

    def test_components_preceding_absolute_component_are_ignored(self):
        self.assertEqual("|c|d", self.filesystem.joinpaths("a", "|b", "|c", "d"))

    def test_one_separator_added_for_trailing_empty_components(self):
        self.assertEqual("a|", self.filesystem.joinpaths("a", ""))
        self.assertEqual("a|", self.filesystem.joinpaths("a", "", ""))

    def test_no_separator_added_for_leading_empty_components(self):
        self.assertEqual("a", self.filesystem.joinpaths("", "a"))

    def test_internal_empty_components_ignored(self):
        self.assertEqual("a|b", self.filesystem.joinpaths("a", "", "b"))
        self.assertEqual("a|b|", self.filesystem.joinpaths("a|", "", "b|"))


class PathSeparatorTest(TestCase):
    def test_os_path_sep_matches_fake_filesystem_separator(self):
        filesystem = fake_filesystem.FakeFilesystem(path_separator="!")
        fake_os_module = fake_os.FakeOsModule(filesystem)
        self.assertEqual("!", fake_os_module.sep)
        self.assertEqual("!", fake_os_module.path.sep)


class NormalizeCaseTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.filesystem.is_case_sensitive = False

    def test_normalize_case(self):
        self.filesystem.create_file("/Foo/Bar")
        self.assertEqual(
            f"{self.filesystem.root_dir_name}Foo/Bar",
            self.filesystem._original_path("/foo/bar"),
        )
        self.assertEqual(
            f"{self.filesystem.root_dir_name}Foo/Bar",
            self.filesystem._original_path("/FOO/BAR"),
        )

    def test_normalize_case_for_drive(self):
        self.filesystem.is_windows_fs = True
        self.filesystem.create_file("C:/Foo/Bar")
        self.assertEqual("C:/Foo/Bar", self.filesystem._original_path("c:/foo/bar"))
        self.assertEqual("C:/Foo/Bar", self.filesystem._original_path("C:/FOO/BAR"))

    def test_normalize_case_for_non_existing_file(self):
        self.filesystem.create_dir("/Foo/Bar")
        self.assertEqual(
            f"{self.filesystem.root_dir_name}Foo/Bar/baz",
            self.filesystem._original_path("/foo/bar/baz"),
        )
        self.assertEqual(
            f"{self.filesystem.root_dir_name}Foo/Bar/BAZ",
            self.filesystem._original_path("/FOO/BAR/BAZ"),
        )

    @unittest.skipIf(
        not TestCase.is_windows, "Regression test for Windows problem only"
    )
    def test_normalize_case_for_lazily_added_empty_file(self):
        # regression test for specific issue with added empty real files
        filesystem = fake_filesystem.FakeFilesystem()
        real_dir_path = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
        filesystem.add_real_directory(real_dir_path)
        initPyPath = os.path.join(real_dir_path, "__init__.py")
        self.assertEqual(initPyPath, filesystem._original_path(initPyPath.upper()))


class AlternativePathSeparatorTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="!")
        self.filesystem.alternative_path_separator = "?"

    def test_initial_value(self):
        filesystem = fake_filesystem.FakeFilesystem()
        if self.is_windows:
            self.assertEqual("/", filesystem.alternative_path_separator)
        else:
            self.assertIsNone(filesystem.alternative_path_separator)

        filesystem = fake_filesystem.FakeFilesystem(path_separator="/")
        self.assertIsNone(filesystem.alternative_path_separator)

    def test_alt_sep(self):
        fake_os_module = fake_os.FakeOsModule(self.filesystem)
        self.assertEqual("?", fake_os_module.altsep)
        self.assertEqual("?", fake_os_module.path.altsep)

    def test_collapse_path_with_mixed_separators(self):
        self.assertEqual("!foo!bar", self.filesystem.normpath("!foo??bar"))

    def test_normalize_path_with_mixed_separators(self):
        path = "foo?..?bar"
        self.assertEqual(
            f"{self.filesystem.root_dir_name}bar",
            self.filesystem.absnormpath(path),
        )

    def test_exists_with_mixed_separators(self):
        self.filesystem.create_file("?foo?bar?baz")
        self.filesystem.create_file("!foo!bar!xyzzy!plugh")
        self.assertTrue(self.filesystem.exists("!foo!bar!baz"))
        self.assertTrue(self.filesystem.exists("?foo?bar?xyzzy?plugh"))


class DriveLetterSupportTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(path_separator="!")
        self.filesystem.alternative_path_separator = "^"
        self.filesystem.is_windows_fs = True

    def test_initial_value(self):
        filesystem = fake_filesystem.FakeFilesystem()
        if self.is_windows:
            self.assertTrue(filesystem.is_windows_fs)
        else:
            self.assertFalse(filesystem.is_windows_fs)

    def test_collapse_path(self):
        self.assertEqual("c:!foo!bar", self.filesystem.normpath("c:!!foo!!bar"))

    def test_collapse_unc_path(self):
        self.assertEqual("!!foo!bar!baz", self.filesystem.normpath("!!foo!bar!!baz!!"))

    def test_normalize_path_str(self):
        self.filesystem.cwd = ""
        self.assertEqual("c:!foo!bar", self.filesystem.absnormpath("c:!foo!!bar"))
        self.filesystem.cwd = "c:!foo"
        self.assertEqual("c:!foo!bar", self.filesystem.absnormpath("bar"))

    def test_normalize_path_bytes(self):
        self.filesystem.cwd = b""
        self.assertEqual(b"c:!foo!bar", self.filesystem.absnormpath(b"c:!foo!!bar"))
        self.filesystem.cwd = b"c:!foo"
        self.assertEqual(b"c:!foo!bar", self.filesystem.absnormpath(b"bar"))

    def test_split_path_str(self):
        self.assertEqual(("c:!foo", "bar"), self.filesystem.splitpath("c:!foo!bar"))
        self.assertEqual(("c:!", "foo"), self.filesystem.splitpath("c:!foo"))
        self.assertEqual(("!foo", "bar"), self.filesystem.splitpath("!foo!bar"))
        self.assertEqual(("!", "foo"), self.filesystem.splitpath("!foo"))
        self.assertEqual(("c:foo", "bar"), self.filesystem.splitpath("c:foo!bar"))
        self.assertEqual(("c:", "foo"), self.filesystem.splitpath("c:foo"))
        self.assertEqual(("foo", "bar"), self.filesystem.splitpath("foo!bar"))

    def test_split_with_alt_separator(self):
        self.assertEqual(("a^b", "c"), self.filesystem.splitpath("a^b^c"))
        self.assertEqual(("a^b!c", "d"), self.filesystem.splitpath("a^b!c^d"))
        self.assertEqual(("a^b!c", "d"), self.filesystem.splitpath("a^b!c!d"))
        self.assertEqual((b"a^b", b"c"), self.filesystem.splitpath(b"a^b^c"))
        self.assertEqual((b"a^b!c", b"d"), self.filesystem.splitpath(b"a^b!c^d"))
        self.assertEqual((b"a^b!c", b"d"), self.filesystem.splitpath(b"a^b!c!d"))

    def test_split_path_bytes(self):
        self.assertEqual((b"c:!foo", b"bar"), self.filesystem.splitpath(b"c:!foo!bar"))
        self.assertEqual((b"c:!", b"foo"), self.filesystem.splitpath(b"c:!foo"))
        self.assertEqual((b"!foo", b"bar"), self.filesystem.splitpath(b"!foo!bar"))
        self.assertEqual((b"!", b"foo"), self.filesystem.splitpath(b"!foo"))
        self.assertEqual((b"c:foo", b"bar"), self.filesystem.splitpath(b"c:foo!bar"))
        self.assertEqual((b"c:", b"foo"), self.filesystem.splitpath(b"c:foo"))
        self.assertEqual((b"foo", b"bar"), self.filesystem.splitpath(b"foo!bar"))

    def test_characters_before_root_ignored_in_join_paths(self):
        self.assertEqual("c:d", self.filesystem.joinpaths("b", "c:", "d"))

    def test_resolve_path(self):
        self.assertEqual("C:!foo!bar", self.filesystem.resolve_path("C:!foo!bar"))

    def test_get_path_components(self):
        self.assertEqual(
            ["c:", "foo", "bar"],
            self.filesystem._path_components("c:!foo!bar"),
        )
        self.assertEqual(["c:"], self.filesystem._path_components("c:"))

    def test_split_drive_str(self):
        self.assertEqual(("c:", "!foo!bar"), self.filesystem.splitdrive("c:!foo!bar"))
        self.assertEqual(("", "!foo!bar"), self.filesystem.splitdrive("!foo!bar"))
        self.assertEqual(("c:", "foo!bar"), self.filesystem.splitdrive("c:foo!bar"))
        self.assertEqual(("", "foo!bar"), self.filesystem.splitdrive("foo!bar"))

    def test_split_drive_bytes(self):
        self.assertEqual(
            (b"c:", b"!foo!bar"), self.filesystem.splitdrive(b"c:!foo!bar")
        )
        self.assertEqual((b"", b"!foo!bar"), self.filesystem.splitdrive(b"!foo!bar"))

    def test_split_drive_alt_sep(self):
        self.assertEqual(("c:", "^foo^bar"), self.filesystem.splitdrive("c:^foo^bar"))
        self.assertEqual(("", "foo^bar"), self.filesystem.splitdrive("foo^bar"))
        self.assertEqual(("", "foo^bar!baz"), self.filesystem.splitdrive("foo^bar!baz"))
        self.assertEqual(
            (b"c:", b"^foo^bar"), self.filesystem.splitdrive(b"c:^foo^bar")
        )
        self.assertEqual((b"", b"^foo^bar"), self.filesystem.splitdrive(b"^foo^bar"))
        self.assertEqual(
            (b"", b"^foo^bar!baz"), self.filesystem.splitdrive(b"^foo^bar!baz")
        )

    def test_split_drive_with_unc_path(self):
        self.assertEqual(
            ("!!foo!bar", "!baz"), self.filesystem.splitdrive("!!foo!bar!baz")
        )
        self.assertEqual(("", "!!foo"), self.filesystem.splitdrive("!!foo"))
        self.assertEqual(("", "!!foo!!bar"), self.filesystem.splitdrive("!!foo!!bar"))
        self.assertEqual(("!!foo!bar", "!!"), self.filesystem.splitdrive("!!foo!bar!!"))

    def test_split_drive_with_unc_path_alt_sep(self):
        self.assertEqual(
            ("^^foo^bar", "!baz"), self.filesystem.splitdrive("^^foo^bar!baz")
        )
        self.assertEqual(("", "^^foo"), self.filesystem.splitdrive("^^foo"))
        self.assertEqual(("", "^^foo^^bar"), self.filesystem.splitdrive("^^foo^^bar"))
        self.assertEqual(("^^foo^bar", "^^"), self.filesystem.splitdrive("^^foo^bar^^"))

    def test_split_path_with_drive(self):
        self.assertEqual(("d:!foo", "baz"), self.filesystem.splitpath("d:!foo!baz"))
        self.assertEqual(("d:!foo!baz", ""), self.filesystem.splitpath("d:!foo!baz!"))
        self.assertEqual(("c:", ""), self.filesystem.splitpath("c:"))
        self.assertEqual(("c:!", ""), self.filesystem.splitpath("c:!"))
        self.assertEqual(("c:!!", ""), self.filesystem.splitpath("c:!!"))

    def test_split_path_with_drive_alt_sep(self):
        self.assertEqual(("d:^foo", "baz"), self.filesystem.splitpath("d:^foo^baz"))
        self.assertEqual(("d:^foo^baz", ""), self.filesystem.splitpath("d:^foo^baz^"))
        self.assertEqual(("c:", ""), self.filesystem.splitpath("c:"))
        self.assertEqual(("c:^", ""), self.filesystem.splitpath("c:^"))
        self.assertEqual(("c:^^", ""), self.filesystem.splitpath("c:^^"))

    def test_split_path_with_unc_path(self):
        self.assertEqual(
            ("!!foo!bar!", "baz"), self.filesystem.splitpath("!!foo!bar!baz")
        )
        self.assertEqual(("!!foo!bar", ""), self.filesystem.splitpath("!!foo!bar"))
        self.assertEqual(("!!foo!bar!!", ""), self.filesystem.splitpath("!!foo!bar!!"))

    def test_split_path_with_unc_path_alt_sep(self):
        self.assertEqual(
            ("^^foo^bar^", "baz"), self.filesystem.splitpath("^^foo^bar^baz")
        )
        self.assertEqual(("^^foo^bar", ""), self.filesystem.splitpath("^^foo^bar"))
        self.assertEqual(("^^foo^bar^^", ""), self.filesystem.splitpath("^^foo^bar^^"))

    def test_splitroot_with_drive(self):
        self.assertEqual(
            ("E:", "!", "foo!bar"), self.filesystem.splitroot("E:!foo!bar")
        )
        self.assertEqual(
            ("E:", "!", "!foo!!!bar"), self.filesystem.splitroot("E:!!foo!!!bar")
        )
        self.assertEqual(
            (b"E:", b"!", b"!foo!!!bar"), self.filesystem.splitroot(b"E:!!foo!!!bar")
        )
        self.assertEqual(
            ("C:", "^", "foo^bar"), self.filesystem.splitroot("C:^foo^bar")
        )

    def test_splitroot_with_unc_path(self):
        self.assertEqual(
            ("!!foo!bar", "!", "baz"), self.filesystem.splitroot("!!foo!bar!baz")
        )
        self.assertEqual(
            ("!!?!UNC", "!", "foo!bar"), self.filesystem.splitroot("!!?!UNC!foo!bar")
        )
        self.assertEqual(
            ("^^foo^bar", "^", "baz"), self.filesystem.splitroot("^^foo^bar^baz")
        )
        self.assertEqual(
            (b"!!foo!bar", b"!", b"baz"), self.filesystem.splitroot(b"!!foo!bar!baz")
        )

    def test_splitroot_with_empty_parts(self):
        self.assertEqual(("", "", ""), self.filesystem.splitroot(""))
        self.assertEqual(("", "!", "foo"), self.filesystem.splitroot("!foo"))
        self.assertEqual(("!!foo!bar", "", ""), self.filesystem.splitroot("!!foo!bar"))
        self.assertEqual(("!!foo", "", ""), self.filesystem.splitroot("!!foo"))
        self.assertEqual(
            ("!!foo!bar", "!", ""), self.filesystem.splitroot("!!foo!bar!")
        )
        self.assertEqual(("C:", "", "foo!bar"), self.filesystem.splitroot("C:foo!bar"))


class DiskSpaceTest(TestCase):
    def setUp(self):
        self.fs = fake_filesystem.FakeFilesystem(path_separator="!", total_size=100)
        self.os = fake_os.FakeOsModule(self.fs)
        self.open = fake_open.FakeFileOpen(self.fs)

    def test_disk_usage_on_file_creation(self):
        total_size = 100
        self.fs.add_mount_point("!mount", total_size)

        def create_too_large_file():
            with self.open("!mount!file", "w") as dest:
                dest.write("a" * (total_size + 1))

        with self.assertRaises(OSError):
            create_too_large_file()

        self.assertEqual(0, self.fs.get_disk_usage("!mount").used)

        with self.open("!mount!file", "w") as dest:
            dest.write("a" * total_size)

        self.assertEqual(total_size, self.fs.get_disk_usage("!mount").used)

    def test_disk_usage_on_automounted_drive(self):
        self.fs.is_windows_fs = True
        self.fs.reset(total_size=100)
        self.fs.create_file("!foo!bar", st_size=50)
        self.assertEqual(0, self.fs.get_disk_usage("D:!").used)
        self.fs.cwd = "E:!foo"
        self.assertEqual(0, self.fs.get_disk_usage("!foo").used)

    def test_disk_usage_on_mounted_paths(self):
        self.fs.add_mount_point("!foo", total_size=200)
        self.fs.add_mount_point("!foo!bar", total_size=400)
        self.fs.create_file("!baz", st_size=50)
        self.fs.create_file("!foo!baz", st_size=60)
        self.fs.create_file("!foo!bar!baz", st_size=100)
        self.assertEqual(50, self.fs.get_disk_usage("!").used)
        self.assertEqual(60, self.fs.get_disk_usage("!foo").used)
        self.assertEqual(100, self.fs.get_disk_usage("!foo!bar").used)
        self.assertEqual(400, self.fs.get_disk_usage("!foo!bar").total)

    def test_file_system_size_after_large_file_creation(self):
        filesystem = fake_filesystem.FakeFilesystem(
            path_separator="!", total_size=1024 * 1024 * 1024 * 100
        )
        filesystem.create_file("!foo!baz", st_size=1024 * 1024 * 1024 * 10)
        self.assertEqual(
            (
                1024 * 1024 * 1024 * 100,
                1024 * 1024 * 1024 * 10,
                1024 * 1024 * 1024 * 90,
            ),
            filesystem.get_disk_usage(),
        )

    def test_file_system_size_after_binary_file_creation(self):
        self.fs.create_file("!foo!bar", contents=b"xyzzy")
        self.assertEqual((100, 5, 95), self.fs.get_disk_usage())

    def test_file_system_size_after_ascii_string_file_creation(self):
        self.fs.create_file("!foo!bar", contents="complicated")
        self.assertEqual((100, 11, 89), self.fs.get_disk_usage())

    def test_filesystem_size_after_2byte_unicode_file_creation(self):
        self.fs.create_file("!foo!bar", contents="сложно", encoding="utf-8")
        self.assertEqual((100, 12, 88), self.fs.get_disk_usage())

    def test_filesystem_size_after_3byte_unicode_file_creation(self):
        self.fs.create_file("!foo!bar", contents="複雑", encoding="utf-8")
        self.assertEqual((100, 6, 94), self.fs.get_disk_usage())

    def test_file_system_size_after_file_deletion(self):
        self.fs.create_file("!foo!bar", contents=b"xyzzy")
        self.fs.create_file("!foo!baz", st_size=20)
        self.fs.remove_object("!foo!bar")
        self.assertEqual((100, 20, 80), self.fs.get_disk_usage())

    def test_file_system_size_after_directory_removal(self):
        self.fs.create_file("!foo!bar", st_size=10)
        self.fs.create_file("!foo!baz", st_size=20)
        self.fs.create_file("!foo1!bar", st_size=40)
        self.fs.remove_object("!foo")
        self.assertEqual((100, 40, 60), self.fs.get_disk_usage())

    def test_creating_file_with_fitting_content(self):
        initial_usage = self.fs.get_disk_usage()

        try:
            self.fs.create_file("!foo!bar", contents=b"a" * 100)
        except OSError:
            self.fail(
                "File with contents fitting into disk space " "could not be written."
            )

        self.assertEqual(initial_usage.used + 100, self.fs.get_disk_usage().used)

    def test_creating_file_with_content_too_large(self):
        def create_large_file():
            self.fs.create_file("!foo!bar", contents=b"a" * 101)

        initial_usage = self.fs.get_disk_usage()

        with self.assertRaises(OSError):
            create_large_file()

        self.assertEqual(initial_usage, self.fs.get_disk_usage())

    def test_creating_file_with_fitting_size(self):
        initial_usage = self.fs.get_disk_usage()

        try:
            self.fs.create_file("!foo!bar", st_size=100)
        except OSError:
            self.fail("File with size fitting into disk space could not be written.")

        self.assertEqual(initial_usage.used + 100, self.fs.get_disk_usage().used)

    def test_creating_file_with_size_too_large(self):
        initial_usage = self.fs.get_disk_usage()

        def create_large_file():
            self.fs.create_file("!foo!bar", st_size=101)

        with self.assertRaises(OSError):
            create_large_file()

        self.assertEqual(initial_usage, self.fs.get_disk_usage())

    def test_resize_file_with_fitting_size(self):
        file_object = self.fs.create_file("!foo!bar", st_size=50)
        try:
            file_object.set_large_file_size(100)
            file_object.set_contents(b"a" * 100)
        except OSError:
            self.fail("Resizing file failed although disk space was sufficient.")

    def test_resize_file_with_size_too_large(self):
        file_object = self.fs.create_file("!foo!bar", st_size=50)
        with self.raises_os_error(errno.ENOSPC):
            file_object.set_large_file_size(200)
        with self.raises_os_error(errno.ENOSPC):
            file_object.set_contents("a" * 150)

    def test_file_system_size_after_directory_rename(self):
        self.fs.create_file("!foo!bar", st_size=20)
        self.os.rename("!foo", "!baz")
        self.assertEqual(20, self.fs.get_disk_usage().used)

    def test_file_system_size_after_file_rename(self):
        self.fs.create_file("!foo!bar", st_size=20)
        self.os.rename("!foo!bar", "!foo!baz")
        self.assertEqual(20, self.fs.get_disk_usage().used)

    def test_that_hard_link_does_not_change_used_size(self):
        file1_path = "test_file1"
        file2_path = "test_file2"
        self.fs.create_file(file1_path, st_size=20)
        self.assertEqual(20, self.fs.get_disk_usage().used)
        # creating a hard link shall not increase used space
        self.os.link(file1_path, file2_path)
        self.assertEqual(20, self.fs.get_disk_usage().used)
        # removing a file shall not decrease used space
        # if a hard link still exists
        self.os.unlink(file1_path)
        self.assertEqual(20, self.fs.get_disk_usage().used)
        self.os.unlink(file2_path)
        self.assertEqual(0, self.fs.get_disk_usage().used)

    def test_that_the_size_of_correct_mount_point_is_used(self):
        self.fs.add_mount_point("!mount_limited", total_size=50)
        self.fs.add_mount_point("!mount_unlimited")

        with self.raises_os_error(errno.ENOSPC):
            self.fs.create_file("!mount_limited!foo", st_size=60)
        with self.raises_os_error(errno.ENOSPC):
            self.fs.create_file("!bar", st_size=110)

        try:
            self.fs.create_file("!foo", st_size=60)
            self.fs.create_file("!mount_limited!foo", st_size=40)
            self.fs.create_file("!mount_unlimited!foo", st_size=1000000)
        except OSError:
            self.fail(
                "File with contents fitting into " "disk space could not be written."
            )

    def test_that_disk_usage_of_correct_mount_point_is_used(self):
        self.fs.add_mount_point("!mount1", total_size=20)
        self.fs.add_mount_point("!mount1!bar!mount2", total_size=50)

        self.fs.create_file("!foo!bar", st_size=10)
        self.fs.create_file("!mount1!foo!bar", st_size=10)
        self.fs.create_file("!mount1!bar!mount2!foo!bar", st_size=10)

        self.assertEqual(90, self.fs.get_disk_usage("!foo").free)
        self.assertEqual(10, self.fs.get_disk_usage("!mount1!foo").free)
        self.assertEqual(40, self.fs.get_disk_usage("!mount1!bar!mount2").free)

    def test_set_larger_disk_size(self):
        self.fs.add_mount_point("!mount1", total_size=20)
        with self.raises_os_error(errno.ENOSPC):
            self.fs.create_file("!mount1!foo", st_size=100)
        self.fs.set_disk_usage(total_size=200, path="!mount1")
        self.fs.create_file("!mount1!foo", st_size=100)
        self.assertEqual(100, self.fs.get_disk_usage("!mount1!foo").free)

    def test_set_smaller_disk_size(self):
        self.fs.add_mount_point("!mount1", total_size=200)
        self.fs.create_file("!mount1!foo", st_size=100)
        with self.raises_os_error(errno.ENOSPC):
            self.fs.set_disk_usage(total_size=50, path="!mount1")
        self.fs.set_disk_usage(total_size=150, path="!mount1")
        self.assertEqual(50, self.fs.get_disk_usage("!mount1!foo").free)

    def test_disk_size_on_unlimited_disk(self):
        self.fs.add_mount_point("!mount1")
        self.fs.create_file("!mount1!foo", st_size=100)
        self.fs.set_disk_usage(total_size=1000, path="!mount1")
        self.assertEqual(900, self.fs.get_disk_usage("!mount1!foo").free)

    def test_disk_size_on_auto_mounted_drive_on_file_creation(self):
        self.fs.is_windows_fs = True
        # drive d: shall be auto-mounted and the used size adapted
        self.fs.create_file("d:!foo!bar", st_size=100)
        self.fs.set_disk_usage(total_size=1000, path="d:")
        self.assertEqual(self.fs.get_disk_usage("d:!foo").free, 900)

    def test_disk_size_on_auto_mounted_drive_on_directory_creation(self):
        self.fs.is_windows_fs = True
        self.fs.create_dir("d:!foo!bar")
        self.fs.create_file("d:!foo!bar!baz", st_size=100)
        self.fs.create_file("d:!foo!baz", st_size=100)
        self.fs.set_disk_usage(total_size=1000, path="d:")
        self.assertEqual(800, self.fs.get_disk_usage("d:!foo").free)

    def test_copying_preserves_byte_contents(self):
        source_file = self.fs.create_file("foo", contents=b"somebytes")
        dest_file = self.fs.create_file("bar")
        dest_file.set_contents(source_file.contents)
        self.assertEqual(dest_file.contents, source_file.contents)

    def test_diskusage_after_open_write(self):
        with self.open("bar.txt", "w") as f:
            f.write("a" * 60)
            f.flush()
        self.assertEqual(60, self.fs.get_disk_usage()[1])

    def test_disk_full_after_reopened(self):
        with self.open("bar.txt", "w") as f:
            f.write("a" * 60)
        with self.open("bar.txt") as f:
            self.assertEqual("a" * 60, f.read())
        with self.raises_os_error(errno.ENOSPC):
            with self.open("bar.txt", "w") as f:
                f.write("b" * 110)
                with self.raises_os_error(errno.ENOSPC):
                    f.flush()
        with self.open("bar.txt") as f:
            self.assertEqual("", f.read())

    def test_disk_full_append(self):
        file_path = "bar.txt"
        with self.open(file_path, "w") as f:
            f.write("a" * 60)
        with self.open(file_path) as f:
            self.assertEqual("a" * 60, f.read())
        with self.raises_os_error(errno.ENOSPC):
            with self.open(file_path, "a") as f:
                f.write("b" * 41)
                with self.raises_os_error(errno.ENOSPC):
                    f.flush()
        with self.open("bar.txt") as f:
            self.assertEqual(f.read(), "a" * 60)

    def test_disk_full_after_reopened_rplus_seek(self):
        with self.open("bar.txt", "w") as f:
            f.write("a" * 60)
        with self.open("bar.txt") as f:
            self.assertEqual(f.read(), "a" * 60)
        with self.raises_os_error(errno.ENOSPC):
            with self.open("bar.txt", "r+") as f:
                f.seek(50)
                f.write("b" * 60)
                with self.raises_os_error(errno.ENOSPC):
                    f.flush()
        with self.open("bar.txt") as f:
            self.assertEqual(f.read(), "a" * 60)


class MountPointTest(TestCase):
    def setUp(self):
        self.filesystem = fake_filesystem.FakeFilesystem(
            path_separator="!", total_size=100
        )

    def add_mount_points(self):
        self.filesystem.add_mount_point("!foo")
        self.filesystem.add_mount_point("!bar")
        self.filesystem.add_mount_point("!foo!baz")

    def test_that_new_mount_points_get_new_device_number(self):
        self.add_mount_points()
        self.assertEqual(1, self.filesystem.get_object("!").st_dev)
        self.assertEqual(2, self.filesystem.get_object("!foo").st_dev)
        self.assertEqual(3, self.filesystem.get_object("!bar").st_dev)
        self.assertEqual(4, self.filesystem.get_object("!foo!baz").st_dev)

    def test_that_new_directories_get_correct_device_number(self):
        self.add_mount_points()
        self.assertEqual(1, self.filesystem.create_dir("!foo1!bar").st_dev)
        self.assertEqual(2, self.filesystem.create_dir("!foo!bar").st_dev)
        self.assertEqual(4, self.filesystem.create_dir("!foo!baz!foo!bar").st_dev)

    def test_that_new_files_get_correct_device_number(self):
        self.add_mount_points()
        self.assertEqual(1, self.filesystem.create_file("!foo1!bar").st_dev)
        self.assertEqual(2, self.filesystem.create_file("!foo!bar").st_dev)
        self.assertEqual(4, self.filesystem.create_file("!foo!baz!foo!bar").st_dev)

    def test_that_mount_point_cannot_be_added_twice(self):
        self.add_mount_points()
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.add_mount_point("!foo")
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.add_mount_point("!foo!")

    def test_that_drives_are_auto_mounted(self):
        self.filesystem.is_windows_fs = True
        self.add_mount_points()
        self.filesystem.create_dir("d:!foo!bar")
        self.filesystem.create_file("d:!foo!baz")
        self.filesystem.create_file("z:!foo!baz")
        self.assertEqual(5, self.filesystem.get_object("d:").st_dev)
        self.assertEqual(5, self.filesystem.get_object("d:!foo!bar").st_dev)
        self.assertEqual(5, self.filesystem.get_object("d:!foo!baz").st_dev)
        self.assertEqual(6, self.filesystem.get_object("z:!foo!baz").st_dev)

    def test_that_drives_are_auto_mounted_case_insensitive(self):
        self.filesystem.is_windows_fs = True
        self.add_mount_points()
        self.filesystem.is_case_sensitive = False
        self.filesystem.create_dir("D:!foo!bar")
        self.filesystem.create_file("e:!foo!baz")
        self.assertEqual(5, self.filesystem.get_object("D:").st_dev)
        self.assertEqual(5, self.filesystem.get_object("d:!foo!bar").st_dev)
        self.assertEqual(6, self.filesystem.get_object("e:!foo").st_dev)
        self.assertEqual(6, self.filesystem.get_object("E:!Foo!Baz").st_dev)

    def test_that_unc_paths_are_auto_mounted(self):
        self.filesystem.is_windows_fs = True
        self.add_mount_points()
        self.filesystem.create_dir("!!foo!bar!baz")
        self.filesystem.create_file("!!foo!bar!bip!bop")
        self.assertEqual(5, self.filesystem.get_object("!!foo!bar").st_dev)
        self.assertEqual(5, self.filesystem.get_object("!!foo!bar!bip!bop").st_dev)


class ConvenienceMethodTest(RealFsTestCase):
    def test_create_link_with_non_existent_parent(self):
        self.skip_if_symlink_not_supported()
        file1_path = self.make_path("test_file1")
        link_path = self.make_path("nonexistent", "test_file2")

        self.filesystem.create_file(file1_path, contents="link test")
        self.assertEqual(self.os.stat(file1_path).st_nlink, 1)
        self.filesystem.create_link(file1_path, link_path)
        self.assertEqual(self.os.stat(file1_path).st_nlink, 2)
        self.assertTrue(self.filesystem.exists(link_path))

    def test_create_symlink_with_non_existent_parent(self):
        self.skip_if_symlink_not_supported()
        file1_path = self.make_path("test_file1")
        link_path = self.make_path("nonexistent", "test_file2")

        self.filesystem.create_file(file1_path, contents="symlink test")
        self.filesystem.create_symlink(link_path, file1_path)
        self.assertTrue(self.filesystem.exists(link_path))
        self.assertTrue(self.filesystem.islink(link_path))


class RealFileSystemAccessTest(RealFsTestCase):
    def setUp(self):
        # use the real path separator to work with the real file system
        self.filesystem = fake_filesystem.FakeFilesystem()
        self.fake_open = fake_filesystem.FakeFileOpen(self.filesystem)
        self.pyfakefs_path = os.path.split(os.path.dirname(os.path.abspath(__file__)))[
            0
        ]
        self.root_path = os.path.split(self.pyfakefs_path)[0]

    def test_add_non_existing_real_file_raises(self):
        nonexisting_path = os.path.join("nonexisting", "test.txt")
        with self.assertRaises(OSError):
            self.filesystem.add_real_file(nonexisting_path)
        self.assertFalse(self.filesystem.exists(nonexisting_path))

    def test_add_non_existing_real_directory_raises(self):
        nonexisting_path = "/nonexisting"
        with self.raises_os_error(errno.ENOENT):
            self.filesystem.add_real_directory(nonexisting_path)
        self.assertFalse(self.filesystem.exists(nonexisting_path))

    def test_existing_fake_file_raises(self):
        real_file_path = __file__
        self.filesystem.create_file(real_file_path)
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.add_real_file(real_file_path)

    def test_existing_fake_directory_raises(self):
        self.filesystem.create_dir(self.root_path)
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.add_real_directory(self.root_path)

    def check_fake_file_stat(self, fake_file, real_file_path, target_path=None):
        if target_path is None or target_path == real_file_path:
            self.assertTrue(self.filesystem.exists(real_file_path))
        else:
            self.assertFalse(self.filesystem.exists(real_file_path))
            self.assertTrue(self.filesystem.exists(target_path))

        real_stat = os.stat(real_file_path)
        self.assertIsNone(fake_file._byte_contents)
        self.assertEqual(fake_file.st_size, real_stat.st_size)
        self.assertAlmostEqual(fake_file.st_ctime, real_stat.st_ctime, places=5)
        self.assertAlmostEqual(fake_file.st_atime, real_stat.st_atime, places=5)
        self.assertAlmostEqual(fake_file.st_mtime, real_stat.st_mtime, places=5)
        self.assertEqual(fake_file.st_uid, real_stat.st_uid)
        self.assertEqual(fake_file.st_gid, real_stat.st_gid)

    def check_read_only_file(self, fake_file, real_file_path):
        with open(real_file_path, "rb") as f:
            real_contents = f.read()
        self.assertEqual(fake_file.byte_contents, real_contents)
        if not is_root():
            with self.raises_os_error(errno.EACCES):
                self.fake_open(real_file_path, "w")
        else:
            with self.fake_open(real_file_path, "w"):
                pass

    def check_writable_file(self, fake_file, real_file_path):
        with open(real_file_path, "rb") as f:
            real_contents = f.read()
        self.assertEqual(fake_file.byte_contents, real_contents)
        with self.fake_open(real_file_path, "wb") as f:
            f.write(b"test")
        with open(real_file_path, "rb") as f:
            real_contents1 = f.read()
        self.assertEqual(real_contents1, real_contents)
        with self.fake_open(real_file_path, "rb") as f:
            fake_contents = f.read()
        self.assertEqual(fake_contents, b"test")

    def test_add_existing_real_file_read_only(self):
        real_file_path = os.path.abspath(__file__)
        fake_file = self.filesystem.add_real_file(real_file_path)
        self.check_fake_file_stat(fake_file, real_file_path)
        self.assertEqual(fake_file.st_mode & 0o333, 0)
        self.check_read_only_file(fake_file, real_file_path)

    def test_add_existing_real_file_read_write(self):
        real_file_path = os.path.realpath(__file__)
        fake_file = self.filesystem.add_real_file(real_file_path, read_only=False)

        self.check_fake_file_stat(fake_file, real_file_path)
        self.assertEqual(fake_file.st_mode, os.stat(real_file_path).st_mode)
        self.check_writable_file(fake_file, real_file_path)

    def test_add_real_file_to_existing_path(self):
        real_file_path = os.path.abspath(__file__)
        self.filesystem.create_file("/foo/bar")
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.add_real_file(real_file_path, target_path="/foo/bar")

    def test_add_real_file_to_non_existing_path(self):
        real_file_path = os.path.abspath(__file__)
        fake_file = self.filesystem.add_real_file(
            real_file_path, target_path="/foo/bar"
        )
        self.check_fake_file_stat(fake_file, real_file_path, target_path="/foo/bar")

    def test_write_to_real_file(self):
        # regression test for #470
        real_file_path = os.path.abspath(__file__)
        self.filesystem.add_real_file(real_file_path, read_only=False)
        with self.fake_open(real_file_path, "w") as f:
            f.write("foo")

        with self.fake_open(real_file_path, "rb") as f:
            self.assertEqual(b"foo", f.read())

    def test_add_existing_real_directory_read_only(self):
        self.filesystem.add_real_directory(self.pyfakefs_path)
        self.assertTrue(self.filesystem.exists(self.pyfakefs_path))
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(self.pyfakefs_path, "fake_filesystem.py")
            )
        )
        self.assertTrue(
            self.filesystem.exists(os.path.join(self.pyfakefs_path, "fake_pathlib.py"))
        )

        file_path = os.path.join(self.pyfakefs_path, "fake_filesystem_shutil.py")
        fake_file = self.filesystem.resolve(file_path)
        self.check_fake_file_stat(fake_file, file_path)
        self.check_read_only_file(fake_file, file_path)

    def test_add_existing_real_directory_tree(self):
        self.filesystem.add_real_directory(self.root_path)
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fake_filesystem_test.py",
                )
            )
        )
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(self.root_path, "pyfakefs", "fake_filesystem.py")
            )
        )
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(self.root_path, "pyfakefs", "__init__.py")
            )
        )

    @contextlib.contextmanager
    def create_symlinks(self, symlinks):
        for link in symlinks:
            os.symlink(link[0], link[1])

        yield

        for link in symlinks:
            os.unlink(link[1])

    def test_add_existing_real_directory_symlink(self):
        fake_open = fake_filesystem.FakeFileOpen(self.filesystem)
        real_directory = os.path.join(self.root_path, "pyfakefs", "tests")
        symlinks = [
            (
                "..",
                os.path.join(real_directory, "fixtures", "symlink_dir_relative"),
            ),
            (
                "../all_tests.py",
                os.path.join(real_directory, "fixtures", "symlink_file_relative"),
            ),
            (
                real_directory,
                os.path.join(real_directory, "fixtures", "symlink_dir_absolute"),
            ),
            (
                os.path.join(real_directory, "all_tests.py"),
                os.path.join(real_directory, "fixtures", "symlink_file_absolute"),
            ),
            (
                "/etc/something",
                os.path.join(
                    real_directory, "fixtures", "symlink_file_absolute_outside"
                ),
            ),
        ]

        self.filesystem.create_file("/etc/something")

        with fake_open("/etc/something", "w") as f:
            f.write("good morning")

        try:
            with self.create_symlinks(symlinks):
                self.filesystem.add_real_directory(real_directory, lazy_read=False)
        except OSError:
            if self.is_windows:
                raise unittest.SkipTest("Symlinks under Windows need admin privileges")
            raise

        for link in symlinks:
            self.assertTrue(self.filesystem.islink(link[1]))

        # relative
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fixtures/symlink_dir_relative",
                )
            )
        )
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fixtures/symlink_dir_relative/all_tests.py",
                )
            )
        )
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fixtures/symlink_file_relative",
                )
            )
        )

        # absolute
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fixtures/symlink_dir_absolute",
                )
            )
        )
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fixtures/symlink_dir_absolute/all_tests.py",
                )
            )
        )
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fixtures/symlink_file_absolute",
                )
            )
        )

        # outside
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fixtures/symlink_file_absolute_outside",
                )
            )
        )
        self.assertEqual(
            fake_open(
                os.path.join(
                    self.root_path,
                    "pyfakefs",
                    "tests",
                    "fixtures/symlink_file_absolute_outside",
                )
            ).read(),
            "good morning",
        )

    def test_add_existing_real_directory_symlink_target_path(self):
        self.skip_if_symlink_not_supported(force_real_fs=True)
        real_directory = os.path.join(self.root_path, "pyfakefs", "tests")
        symlinks = [
            (
                "..",
                os.path.join(real_directory, "fixtures", "symlink_dir_relative"),
            ),
            (
                "../all_tests.py",
                os.path.join(real_directory, "fixtures", "symlink_file_relative"),
            ),
        ]

        with self.create_symlinks(symlinks):
            self.filesystem.add_real_directory(
                real_directory, target_path="/path", lazy_read=False
            )

        self.assertTrue(self.filesystem.exists("/path/fixtures/symlink_dir_relative"))
        self.assertTrue(
            self.filesystem.exists("/path/fixtures/symlink_dir_relative/all_tests.py")
        )
        self.assertTrue(self.filesystem.exists("/path/fixtures/symlink_file_relative"))

    def test_add_existing_real_directory_symlink_lazy_read(self):
        self.skip_if_symlink_not_supported(force_real_fs=True)
        real_directory = os.path.join(self.root_path, "pyfakefs", "tests")
        symlinks = [
            (
                "..",
                os.path.join(real_directory, "fixtures", "symlink_dir_relative"),
            ),
            (
                "../all_tests.py",
                os.path.join(real_directory, "fixtures", "symlink_file_relative"),
            ),
        ]

        with self.create_symlinks(symlinks):
            self.filesystem.add_real_directory(
                real_directory, target_path="/path", lazy_read=True
            )

            self.assertTrue(
                self.filesystem.exists("/path/fixtures/symlink_dir_relative")
            )
            self.assertTrue(
                self.filesystem.exists(
                    "/path/fixtures/symlink_dir_relative/all_tests.py"
                )
            )
            self.assertTrue(
                self.filesystem.exists("/path/fixtures/symlink_file_relative")
            )

    def test_add_existing_real_directory_tree_to_existing_path(self):
        self.filesystem.create_dir("/foo/bar")
        with self.raises_os_error(errno.EEXIST):
            self.filesystem.add_real_directory(self.root_path, target_path="/foo/bar")

    def test_add_existing_real_directory_tree_to_other_path(self):
        self.filesystem.add_real_directory(self.root_path, target_path="/foo/bar")
        self.assertFalse(
            self.filesystem.exists(
                os.path.join(self.pyfakefs_path, "tests", "fake_filesystem_test.py")
            )
        )
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(
                    "foo",
                    "bar",
                    "pyfakefs",
                    "tests",
                    "fake_filesystem_test.py",
                )
            )
        )
        self.assertFalse(
            self.filesystem.exists(
                os.path.join(self.root_path, "pyfakefs", "fake_filesystem.py")
            )
        )
        self.assertTrue(
            self.filesystem.exists(
                os.path.join("foo", "bar", "pyfakefs", "__init__.py")
            )
        )

    def test_get_object_from_lazily_added_real_directory(self):
        self.filesystem.is_case_sensitive = True
        self.filesystem.add_real_directory(self.root_path)
        self.assertTrue(
            self.filesystem.get_object(
                os.path.join(self.root_path, "pyfakefs", "fake_filesystem.py")
            )
        )
        self.assertTrue(
            self.filesystem.get_object(
                os.path.join(self.root_path, "pyfakefs", "__init__.py")
            )
        )

    def test_add_existing_real_directory_lazily(self):
        disk_size = 1024 * 1024 * 1024
        real_dir_path = os.path.join(self.root_path, "pyfakefs")
        self.filesystem.set_disk_usage(disk_size, real_dir_path)
        self.filesystem.add_real_directory(real_dir_path)

        # the directory contents have not been read, the the disk usage
        # has not changed
        self.assertEqual(disk_size, self.filesystem.get_disk_usage(real_dir_path).free)
        # checking for existence shall read the directory contents
        self.assertTrue(
            self.filesystem.get_object(
                os.path.join(real_dir_path, "fake_filesystem.py")
            )
        )
        # so now the free disk space shall have decreased
        self.assertGreater(
            disk_size, self.filesystem.get_disk_usage(real_dir_path).free
        )

    def test_add_existing_real_directory_not_lazily(self):
        disk_size = 1024 * 1024 * 1024
        self.filesystem.set_disk_usage(disk_size, self.pyfakefs_path)
        self.filesystem.add_real_directory(self.pyfakefs_path, lazy_read=False)

        # the directory has been read, so the file sizes have
        # been subtracted from the free space
        self.assertGreater(
            disk_size, self.filesystem.get_disk_usage(self.pyfakefs_path).free
        )

    def test_add_existing_real_directory_read_write(self):
        self.filesystem.add_real_directory(self.pyfakefs_path, read_only=False)
        self.assertTrue(self.filesystem.exists(self.pyfakefs_path))
        self.assertTrue(
            self.filesystem.exists(
                os.path.join(self.pyfakefs_path, "fake_filesystem.py")
            )
        )
        self.assertTrue(
            self.filesystem.exists(os.path.join(self.pyfakefs_path, "fake_pathlib.py"))
        )

        file_path = os.path.join(self.pyfakefs_path, "pytest_plugin.py")
        fake_file = self.filesystem.resolve(file_path)
        self.check_fake_file_stat(fake_file, file_path)
        self.check_writable_file(fake_file, file_path)

    def test_add_existing_real_paths_read_only(self):
        real_file_path = os.path.realpath(__file__)
        fixture_path = os.path.join(self.pyfakefs_path, "tests", "fixtures")
        self.filesystem.add_real_paths([real_file_path, fixture_path])

        fake_file = self.filesystem.resolve(real_file_path)
        self.check_fake_file_stat(fake_file, real_file_path)
        self.check_read_only_file(fake_file, real_file_path)

        real_file_path = os.path.join(fixture_path, "module_with_attributes.py")
        fake_file = self.filesystem.resolve(real_file_path)
        self.check_fake_file_stat(fake_file, real_file_path)
        self.check_read_only_file(fake_file, real_file_path)

    def test_add_existing_real_paths_read_write(self):
        real_file_path = os.path.realpath(__file__)
        fixture_path = os.path.join(self.pyfakefs_path, "tests", "fixtures")
        self.filesystem.add_real_paths([real_file_path, fixture_path], read_only=False)

        fake_file = self.filesystem.resolve(real_file_path)
        self.check_fake_file_stat(fake_file, real_file_path)
        self.check_writable_file(fake_file, real_file_path)

        real_file_path = os.path.join(fixture_path, "module_with_attributes.py")
        fake_file = self.filesystem.resolve(real_file_path)
        self.check_fake_file_stat(fake_file, real_file_path)
        self.check_writable_file(fake_file, real_file_path)


class FileSideEffectTests(TestCase):
    def side_effect(self):
        test_case = self
        test_case.side_effect_called = False

        def __side_effect(file_object):
            test_case.side_effect_called = True
            test_case.side_effect_file_object_content = file_object.contents

        return __side_effect

    def setUp(self):
        # use the real path separator to work with the real file system
        self.filesystem = fake_filesystem.FakeFilesystem()
        self.filesystem.create_file("/a/b/file_one", side_effect=self.side_effect())

    def test_side_effect_called(self):
        fake_open = fake_filesystem.FakeFileOpen(self.filesystem)
        self.side_effect_called = False
        with fake_open("/a/b/file_one", "w") as handle:
            handle.write("foo")
        self.assertTrue(self.side_effect_called)

    def test_side_effect_file_object(self):
        fake_open = fake_filesystem.FakeFileOpen(self.filesystem)
        self.side_effect_called = False
        with fake_open("/a/b/file_one", "w") as handle:
            handle.write("foo")
        self.assertEqual(self.side_effect_file_object_content, "foo")


if __name__ == "__main__":
    unittest.main()

Youez - 2016 - github.com/yon3zu
LinuXploit