/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_osutils.py

  • Committer: Jelmer Vernooij
  • Date: 2020-05-24 00:39:50 UTC
  • mto: This revision was merged to the branch mainline in revision 7504.
  • Revision ID: jelmer@jelmer.uk-20200524003950-bbc545r76vc5yajg
Add github action.

Show diffs side-by-side

added added

removed removed

Lines of Context:
818
818
                          osutils.safe_utf8, b'\xbb\xbb')
819
819
 
820
820
 
 
821
class TestSafeRevisionId(tests.TestCase):
 
822
 
 
823
    def test_from_ascii_string(self):
 
824
        # this shouldn't give a warning because it's getting an ascii string
 
825
        self.assertEqual(b'foobar', osutils.safe_revision_id(b'foobar'))
 
826
 
 
827
    def test_from_unicode_string_ascii_contents(self):
 
828
        self.assertRaises(TypeError,
 
829
                          osutils.safe_revision_id, u'bargam')
 
830
 
 
831
    def test_from_unicode_string_unicode_contents(self):
 
832
        self.assertRaises(TypeError,
 
833
                          osutils.safe_revision_id, u'bargam\xae')
 
834
 
 
835
    def test_from_utf8_string(self):
 
836
        self.assertEqual(b'foo\xc2\xae',
 
837
                         osutils.safe_revision_id(b'foo\xc2\xae'))
 
838
 
 
839
    def test_none(self):
 
840
        """Currently, None is a valid revision_id"""
 
841
        self.assertEqual(None, osutils.safe_revision_id(None))
 
842
 
 
843
 
 
844
class TestSafeFileId(tests.TestCase):
 
845
 
 
846
    def test_from_ascii_string(self):
 
847
        self.assertEqual(b'foobar', osutils.safe_file_id(b'foobar'))
 
848
 
 
849
    def test_from_unicode_string_ascii_contents(self):
 
850
        self.assertRaises(TypeError, osutils.safe_file_id, u'bargam')
 
851
 
 
852
    def test_from_unicode_string_unicode_contents(self):
 
853
        self.assertRaises(TypeError,
 
854
                          osutils.safe_file_id, u'bargam\xae')
 
855
 
 
856
    def test_from_utf8_string(self):
 
857
        self.assertEqual(b'foo\xc2\xae',
 
858
                         osutils.safe_file_id(b'foo\xc2\xae'))
 
859
 
 
860
    def test_none(self):
 
861
        """Currently, None is a valid revision_id"""
 
862
        self.assertEqual(None, osutils.safe_file_id(None))
 
863
 
 
864
 
821
865
class TestSendAll(tests.TestCase):
822
866
 
823
867
    def test_send_with_disconnected_socket(self):
2093
2137
        self.assertEqual(self.gid, s.st_gid)
2094
2138
 
2095
2139
 
 
2140
class TestPathFromEnviron(tests.TestCase):
 
2141
 
 
2142
    def test_is_unicode(self):
 
2143
        self.overrideEnv('BRZ_TEST_PATH', './anywhere at all/')
 
2144
        path = osutils.path_from_environ('BRZ_TEST_PATH')
 
2145
        self.assertIsInstance(path, str)
 
2146
        self.assertEqual(u'./anywhere at all/', path)
 
2147
 
 
2148
    def test_posix_path_env_ascii(self):
 
2149
        self.overrideEnv('BRZ_TEST_PATH', '/tmp')
 
2150
        home = osutils._posix_path_from_environ('BRZ_TEST_PATH')
 
2151
        self.assertIsInstance(home, str)
 
2152
        self.assertEqual(u'/tmp', home)
 
2153
 
 
2154
    def test_posix_path_env_unicode(self):
 
2155
        self.requireFeature(features.ByteStringNamedFilesystem)
 
2156
        self.overrideEnv('BRZ_TEST_PATH', '/home/\xa7test')
 
2157
        self.overrideAttr(osutils, "_fs_enc", "iso8859-1")
 
2158
        self.assertEqual(u'/home/\xa7test',
 
2159
                         osutils._posix_path_from_environ('BRZ_TEST_PATH'))
 
2160
        osutils._fs_enc = "iso8859-5"
 
2161
        # In Python 3, os.environ returns unicode.
 
2162
        self.assertEqual(u'/home/\xa7test',
 
2163
                         osutils._posix_path_from_environ('BRZ_TEST_PATH'))
 
2164
 
 
2165
 
2096
2166
class TestGetHomeDir(tests.TestCase):
2097
2167
 
2098
2168
    def test_is_unicode(self):
2212
2282
            osutils.find_executable_on_path('THIS SHOULD NOT EXIST') is None)
2213
2283
 
2214
2284
 
 
2285
class TestEnvironmentErrors(tests.TestCase):
 
2286
    """Test handling of environmental errors"""
 
2287
 
 
2288
    def test_is_oserror(self):
 
2289
        self.assertTrue(osutils.is_environment_error(
 
2290
            OSError(errno.EINVAL, "Invalid parameter")))
 
2291
 
 
2292
    def test_is_ioerror(self):
 
2293
        self.assertTrue(osutils.is_environment_error(
 
2294
            IOError(errno.EINVAL, "Invalid parameter")))
 
2295
 
 
2296
    def test_is_socket_error(self):
 
2297
        self.assertTrue(osutils.is_environment_error(
 
2298
            socket.error(errno.EINVAL, "Invalid parameter")))
 
2299
 
 
2300
    def test_is_select_error(self):
 
2301
        self.assertTrue(osutils.is_environment_error(
 
2302
            select.error(errno.EINVAL, "Invalid parameter")))
 
2303
 
 
2304
    def test_is_pywintypes_error(self):
 
2305
        self.requireFeature(features.pywintypes)
 
2306
        import pywintypes
 
2307
        self.assertTrue(osutils.is_environment_error(
 
2308
            pywintypes.error(errno.EINVAL, "Invalid parameter", "Caller")))
 
2309
 
 
2310
 
2215
2311
class SupportsExecutableTests(tests.TestCaseInTempDir):
2216
2312
 
2217
2313
    def test_returns_bool(self):