Пример #1
0
    def test_decode_success(self):
        # Test that encoded project tree node paths decode to the expected values.

        path = TreeNamePath.from_str('/abc/def')
        decoded_path = decode_project_tree_node_path(str(path).encode('utf-8'))
        self.assertEqual(path, decoded_path)

        path = TreeNamePath.from_str('/')
        decoded_path = decode_project_tree_node_path(str(path).encode('utf-8'))
        self.assertEqual(path, decoded_path)
Пример #2
0
    def test_encode_success(self):
        # Test that project tree node paths encode to the expected values.

        data = encode_project_tree_node_path(TreeNamePath.from_str('/'))
        self.assertEqual(data.decode('utf-8'), '/')

        data = encode_project_tree_node_path(
            TreeNamePath.from_str('/childDir0'))
        self.assertEqual(data.decode('utf-8'), '/childDir0')

        data = encode_project_tree_node_path(
            TreeNamePath.from_str('/childDir1'))
        self.assertEqual(data.decode('utf-8'), '/childDir1')

        data = encode_project_tree_node_path(
            TreeNamePath.from_str('/childDir0/grandchildSeq'))
        self.assertEqual(data.decode('utf-8'), '/childDir0/grandchildSeq')
    def test_from_str_success(self):
        # Test the from_str method in cases where it should succeed.

        path = TreeNamePath.from_str('/')
        self.assertSequenceEqual(path.path_names, [])
        self.assertTrue(path.is_absolute)

        path = TreeNamePath.from_str('')
        self.assertSequenceEqual(path.path_names, [])
        self.assertFalse(path.is_absolute)

        path = TreeNamePath.from_str('/abc/def/ghi')
        self.assertSequenceEqual(path.path_names, ['abc', 'def', 'ghi'])
        self.assertTrue(path.is_absolute)

        path = TreeNamePath.from_str('abc/def/ghi')
        self.assertSequenceEqual(path.path_names, ['abc', 'def', 'ghi'])
        self.assertFalse(path.is_absolute)
Пример #4
0
def decode_project_tree_node_path(data):
    """Decodes a path-based reference to a project tree node.
  Suitable for use with the PROJECT_TREE_NODE_PATH_MEDIA_TYPE media type.
  Returns the decoded path as a TreeNamePath object.
  """
    path = TreeNamePath.from_str(bytes(data).decode(MEDIA_STR_ENCODING))
    if not path.is_absolute:
        raise ValueError(
            QCoreApplication.translate(
                'MIMEData', 'Expected an absolute path, got a relative path.'))
    return path
Пример #5
0
def decode_seq_component_tree_node_path(data):
    """Decodes a path-based reference to a sequence component tree node.
  Suitable for use with the SEQUENCE_COMPONENT_TREE_NODE_PATH_MEDIA_TYPE media type.
  Returns the decoded paths as a 2-tuple containing the project tree node's absolute path and the sequence component
  node's absolute path.
  """
    project_tree_path_bytes, seq_component_tree_path_bytes = pickle.loads(
        bytes(data))
    project_tree_path = TreeNamePath.from_str(
        project_tree_path_bytes.decode(MEDIA_STR_ENCODING))
    seq_component_tree_path = TreeNamePath.from_str(
        seq_component_tree_path_bytes.decode(MEDIA_STR_ENCODING))

    if not project_tree_path.is_absolute:
        raise ValueError(
            QCoreApplication.translate(
                'MIMEData', 'Expected an absolute path, got a relative path.'))
    if not seq_component_tree_path.is_absolute:
        raise ValueError(
            QCoreApplication.translate(
                'MIMEData', 'Expected an absolute path, got a relative path.'))

    return (project_tree_path, seq_component_tree_path)
    def test_hash(self):
        # Test that equal TreeNamePaths have equal hash values.

        path0 = TreeNamePath.from_str('/abc/def')
        path1 = TreeNamePath.from_str('/abc/def')
        self.assertEqual(hash(path0), hash(path1))

        path0 = TreeNamePath.from_str('abc/def')
        path1 = TreeNamePath.from_str('abc/def')
        self.assertEqual(hash(path0), hash(path1))

        path0 = TreeNamePath.from_str('/')
        path1 = TreeNamePath.from_str('/')
        self.assertEqual(hash(path0), hash(path1))

        path0 = TreeNamePath.from_str('')
        path1 = TreeNamePath.from_str('')
        self.assertEqual(hash(path0), hash(path1))
    def test_equality(self):
        # Test equality checking for TreeNamePaths.

        path0 = TreeNamePath.from_str('/abc/def')
        path1 = TreeNamePath.from_str('/abc/def')
        self.assertEqual(path0, path1)

        path0 = TreeNamePath.from_str('abc/def')
        path1 = TreeNamePath.from_str('/abc/def')
        self.assertNotEqual(path0, path1)

        path0 = TreeNamePath.from_str('abc/def')
        path1 = TreeNamePath.from_str('abc/ghi')
        self.assertNotEqual(path0, path1)
Пример #8
0
 def test_encode_fail(self):
     # Test that project tree node path encoding fails when expected.
     self.assertRaises(ValueError, encode_project_tree_node_path,
                       TreeNamePath.from_str('abc/def'))
     self.assertRaises(ValueError, encode_project_tree_node_path,
                       TreeNamePath.from_str(''))