Code Monkey home page Code Monkey logo

Comments (9)

fabiocaccamo avatar fabiocaccamo commented on May 20, 2024

@Loreton note that the copy method just do a normal dict.copy and cast it to benedict

https://github.com/fabiocaccamo/python-benedict/blob/master/benedict/dicts/__init__.py#L56

Could you try to repeat the same test using the standard dict please?

from python-benedict.

Loreton avatar Loreton commented on May 20, 2024

Sure...

--- s01_ptr:
{
    "alias": "ptr_alias",   <--- changed
    "credentials": {
        "password": "s01_passw",
        "username": "ptr_unsername"   <--- changed
    },
    "host": "s01_host",
    "location": {
        "building": "ptr_building",   <--- changed
        "floar": "s01_floar",
        "room": "s01_room"
    },
    "ssh_port": "s01_port"
}

--- s01_copy:
{
    "alias": "ptr_alias",   <--- changed
    "credentials": {
        "password": "s01_passw",
        "username": "ptr_unsername"   <--- changed
    },
    "host": "s01_host",
    "location": {
        "building": "ptr_building",   <--- changed
        "floar": "s01_floar",
        "room": "s01_room"
    },
    "ssh_port": "s01_port"
}

--- servers:
{
    "SERVER": {
        "S01": {
            "alias": "ptr_alias",   <--- changed
            "credentials": {
                "password": "s01_passw",
                "username": "ptr_unsername"   <--- changed
            },
            "host": "s01_host",
            "location": {
                "building": "ptr_building",   <--- changed
                "floar": "s01_floar",
                "room": "s01_room"
            },
            "ssh_port": "s01_port"
        }
    }
}
 s01_ptr  == s01_copy? True
 s01_ptr  == SERVER[S01]? True
 s01_copy == SERVER[S01]? True

In this case s01_copy is the same as s01_ptr therefore it may not be considered.

Attached simple script to test the problem. You can enter 'benedict' or 'standard' to test one of them.
Regards
loreto
Benedict_test02a.zip

from python-benedict.

fabiocaccamo avatar fabiocaccamo commented on May 20, 2024

@Loreton thank you, I will test it as soon as possible.

from python-benedict.

fabiocaccamo avatar fabiocaccamo commented on May 20, 2024

@Loreton in the test02 you attached, you are not copying the dict:

s01_ptr=servers['SERVER']['S01']
s01_copy=servers['SERVER']['S01'] # <- this should be: s01_copy=servers['SERVER']['S01'].copy()

from python-benedict.

fabiocaccamo avatar fabiocaccamo commented on May 20, 2024

@Loreton I added a test case for this issue: b9dfedf, it seems that the same error occurs with dict.

I would ask you to check and test it, to run this specific test you should do:

  • For each test method comment @unittest.skip decorator
  • Run python -m unittest tests.github.test_issue_0025

from python-benedict.

Loreton avatar Loreton commented on May 20, 2024

@fabiocaccamo
You are right.
It was my mistake to include the .copy() example because it might take us out of the main purpose. My purpose is to figure out how to make a pointer using benedict (). If the following statement:

s01_ptr=benedict(servers['SERVER.S01'])

is the correct one to get a dict_pointer, then we have a different behavior from the standard:

s01_ptr=servers['SERVER']['S01']

If the statement was not correct, please help me to get the right sintax.
It almost seems that benedict() behaves like a shallow copy.

benedit dict result

--- s01_ptr:
{
    "alias": "ptr_alias",
    "credentials": {
        "password": "s01_passw",
        "username": "ptr_unsername"
    },
    "host": "s01_host",
    "location": {
        "building": "ptr_building",
        "floar": "s01_floar",
        "room": "s01_room"
    },
    "ssh_port": "s01_port",
    "z_ptr_add_item": 1224
}

--- servers:
{
    "SERVER": {
        "S01": {
            "alias": "s01_alias",
            "credentials": {
                "password": "s01_passw",
                "username": "ptr_unsername"
            },
            "host": "s01_host",
            "location": {
                "building": "ptr_building",
                "floar": "s01_floar",
                "room": "s01_room"
            },
            "ssh_port": "s01_port"
        }
    }
}

s01_ptr  == SERVER[S01]? False    <---  benedict dict

Standard dict result:

--- s01_ptr:
{
    "alias": "ptr_alias",
    "credentials": {
        "password": "s01_passw",
        "username": "ptr_unsername"
    },
    "host": "s01_host",
    "location": {
        "building": "ptr_building",
        "floar": "s01_floar",
        "room": "s01_room"
    },
    "ssh_port": "s01_port",
    "z_ptr_add_item": 1224
}

--- servers:
{
    "SERVER": {
        "S01": {
            "alias": "ptr_alias",
            "credentials": {
                "password": "s01_passw",
                "username": "ptr_unsername"
            },
            "host": "s01_host",
            "location": {
                "building": "ptr_building",
                "floar": "s01_floar",
                "room": "s01_room"
            },
            "ssh_port": "s01_port",
            "z_ptr_add_item": 1224
        }
    }
}

s01_ptr  == SERVER[S01]? True   <---   Standard dict

I hope now it's clearer and I'm sorry for the confusion I may have created.
Loreto

Attached new script without the copy() statement.

Benedict_test02c.zip

from python-benedict.

fabiocaccamo avatar fabiocaccamo commented on May 20, 2024

@Loreton could you please modify the test that I added to the tests suite?

from python-benedict.

Loreton avatar Loreton commented on May 20, 2024

@fabiocaccamo - Attached the modified tests suite file

github_issue_0025_test_case.zip

from python-benedict.

fabiocaccamo avatar fabiocaccamo commented on May 20, 2024

@Loreton the attached test is still not valid, check the difference with the updated test on master.

from python-benedict.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.