2323import unittest
2424
2525from pyfakefs import fake_filesystem , fake_os , fake_open
26- from pyfakefs .helpers import IS_PYPY
26+ from pyfakefs .tests . test_utils import skip_if_symlink_not_supported
2727
2828
2929def sep (path ):
@@ -81,6 +81,7 @@ def _create_test_file(self, file_type, path, contents=None):
8181 fh .close ()
8282 # l for symlink, h for hard link
8383 if file_type in ("l" , "h" ):
84+ contents = sep (contents )
8485 real_target , fake_target = (contents , contents )
8586 # If it begins with '/', make it relative to the base. You can't go
8687 # creating files in / for the real file system.
@@ -375,13 +376,16 @@ def assertOsPathMethodBehaviorMatches(
375376
376377 def assertAllOsBehaviorsMatch (self , path ):
377378 path = sep (path )
378- os_method_names = [] if self . is_windows else [ "readlink" ]
379+ os_method_names = ["readlink" ]
379380 os_method_names_no_args = ["getcwd" ]
380- os_path_method_names = ["isabs" , "isdir" ]
381- if not self .is_windows :
382- os_path_method_names += ["islink" , "lexists" ]
383- if not self .is_windows or not IS_PYPY :
384- os_path_method_names += ["isfile" , "exists" ]
381+ os_path_method_names = [
382+ "isabs" ,
383+ "isdir" ,
384+ "islink" ,
385+ "lexists" ,
386+ "isfile" ,
387+ "exists" ,
388+ ]
385389
386390 wrapped_methods = [
387391 ["access" , self ._access_real , self ._access_fake ],
@@ -557,34 +561,33 @@ def test_file_with_binary_contents(self):
557561 self ._create_test_file ("b" , "aFile" , b"some contents" )
558562 self .assertAllOsBehaviorsMatch ("aFile" )
559563
560- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
561564 def test_sym_link_to_empty_file (self ):
565+ skip_if_symlink_not_supported ()
562566 self ._create_test_file ("f" , "aFile" )
563567 self ._create_test_file ("l" , "link_to_empty" , "aFile" )
564568 self .assertAllOsBehaviorsMatch ("link_to_empty" )
565569
566- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
567570 def test_hard_link_to_empty_file (self ):
571+ skip_if_symlink_not_supported ()
568572 self ._create_test_file ("f" , "aFile" )
569573 self ._create_test_file ("h" , "link_to_empty" , "aFile" )
570574 self .assertAllOsBehaviorsMatch ("link_to_empty" )
571575
572- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
573576 def test_sym_link_to_real_file (self ):
577+ skip_if_symlink_not_supported ()
574578 self ._create_test_file ("f" , "aFile" , "some contents" )
575579 self ._create_test_file ("l" , "link_to_file" , "aFile" )
576580 self .assertAllOsBehaviorsMatch ("link_to_file" )
577581
578- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
579582 def test_hard_link_to_real_file (self ):
583+ skip_if_symlink_not_supported ()
580584 self ._create_test_file ("f" , "aFile" , "some contents" )
581585 self ._create_test_file ("h" , "link_to_file" , "aFile" )
582586 self .assertAllOsBehaviorsMatch ("link_to_file" )
583587
584- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
585588 def test_broken_sym_link (self ):
589+ skip_if_symlink_not_supported ()
586590 self ._create_test_file ("l" , "broken_link" , "broken" )
587- self ._create_test_file ("l" , "loop" , "/a/loop" )
588591 self .assertAllOsBehaviorsMatch ("broken_link" )
589592
590593 def test_file_in_a_folder (self ):
@@ -593,16 +596,16 @@ def test_file_in_a_folder(self):
593596 self ._create_test_file ("f" , "a/b/file" , "contents" )
594597 self .assertAllOsBehaviorsMatch ("a/b/file" )
595598
596- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
597599 def test_absolute_sym_link_to_folder (self ):
600+ skip_if_symlink_not_supported ()
598601 self ._create_test_file ("d" , "a" )
599602 self ._create_test_file ("d" , "a/b" )
600603 self ._create_test_file ("f" , "a/b/file" , "contents" )
601604 self ._create_test_file ("l" , "a/link" , "/a/b" )
602605 self .assertAllOsBehaviorsMatch ("a/link/file" )
603606
604- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
605607 def test_link_to_folder_after_chdir (self ):
608+ skip_if_symlink_not_supported ()
606609 self ._create_test_file ("d" , "a" )
607610 self ._create_test_file ("d" , "a/b" )
608611 self ._create_test_file ("f" , "a/b/file" , "contents" )
@@ -613,51 +616,51 @@ def test_link_to_folder_after_chdir(self):
613616 self .fake_os .chdir (fake_dir )
614617 self .assertAllOsBehaviorsMatch ("file" )
615618
616- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
617619 def test_relative_sym_link_to_folder (self ):
620+ skip_if_symlink_not_supported ()
618621 self ._create_test_file ("d" , "a" )
619622 self ._create_test_file ("d" , "a/b" )
620623 self ._create_test_file ("f" , "a/b/file" , "contents" )
621624 self ._create_test_file ("l" , "a/link" , "b" )
622625 self .assertAllOsBehaviorsMatch ("a/link/file" )
623626
624- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
625627 def test_sym_link_to_parent (self ):
628+ skip_if_symlink_not_supported ()
626629 # Soft links on HFS+ / OS X behave differently.
627- if os . uname ()[ 0 ] != "Darwin " :
630+ if sys . platform != "darwin " :
628631 self ._create_test_file ("d" , "a" )
629632 self ._create_test_file ("d" , "a/b" )
630633 self ._create_test_file ("l" , "a/b/c" , ".." )
631634 self .assertAllOsBehaviorsMatch ("a/b/c" )
632635
633- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
634636 def test_path_through_sym_link_to_parent (self ):
637+ skip_if_symlink_not_supported ()
635638 self ._create_test_file ("d" , "a" )
636639 self ._create_test_file ("f" , "a/target" , "contents" )
637640 self ._create_test_file ("d" , "a/b" )
638641 self ._create_test_file ("l" , "a/b/c" , ".." )
639642 self .assertAllOsBehaviorsMatch ("a/b/c/target" )
640643
641- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
642644 def test_sym_link_to_sibling_directory (self ):
645+ skip_if_symlink_not_supported ()
643646 self ._create_test_file ("d" , "a" )
644647 self ._create_test_file ("d" , "a/b" )
645648 self ._create_test_file ("d" , "a/sibling_of_b" )
646649 self ._create_test_file ("f" , "a/sibling_of_b/target" , "contents" )
647650 self ._create_test_file ("l" , "a/b/c" , "../sibling_of_b" )
648651 self .assertAllOsBehaviorsMatch ("a/b/c/target" )
649652
650- @ unittest . skipIf ( TestCase . is_windows , "no symlink in Windows" )
651- def test_sym_link_to_sibling_directory_non_existant_file ( self ):
653+ def test_sym_link_to_sibling_directory_non_existent_file ( self ):
654+ skip_if_symlink_not_supported ()
652655 self ._create_test_file ("d" , "a" )
653656 self ._create_test_file ("d" , "a/b" )
654657 self ._create_test_file ("d" , "a/sibling_of_b" )
655658 self ._create_test_file ("f" , "a/sibling_of_b/target" , "contents" )
656659 self ._create_test_file ("l" , "a/b/c" , "../sibling_of_b" )
657660 self .assertAllOsBehaviorsMatch ("a/b/c/file_does_not_exist" )
658661
659- @unittest .skipIf (TestCase .is_windows , "no symlink in Windows" )
660662 def test_broken_sym_link_to_sibling_directory (self ):
663+ skip_if_symlink_not_supported ()
661664 self ._create_test_file ("d" , "a" )
662665 self ._create_test_file ("d" , "a/b" )
663666 self ._create_test_file ("d" , "a/sibling_of_b" )
0 commit comments