{"id":24543676,"url":"https://github.com/emansarahafi/conditional-operator-inverter","last_synced_at":"2025-03-16T08:08:55.824Z","repository":{"id":271171075,"uuid":"910152186","full_name":"emansarahafi/Conditional-Operator-Inverter","owner":"emansarahafi","description":"This script inverts the conditional operators in a given Python code snippet.","archived":false,"fork":false,"pushed_at":"2024-12-30T16:11:46.000Z","size":1,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T12:52:49.785Z","etag":null,"topics":["astor","conditional-operators","inverter","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emansarahafi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-30T16:11:37.000Z","updated_at":"2024-12-30T16:12:53.000Z","dependencies_parsed_at":"2025-02-17T05:15:29.289Z","dependency_job_id":null,"html_url":"https://github.com/emansarahafi/Conditional-Operator-Inverter","commit_stats":null,"previous_names":["emansarahafi/conditional-operator-inverter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emansarahafi%2FConditional-Operator-Inverter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emansarahafi%2FConditional-Operator-Inverter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emansarahafi%2FConditional-Operator-Inverter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emansarahafi%2FConditional-Operator-Inverter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emansarahafi","download_url":"https://codeload.github.com/emansarahafi/Conditional-Operator-Inverter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841230,"owners_count":20356446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["astor","conditional-operators","inverter","python"],"created_at":"2025-01-22T20:14:41.515Z","updated_at":"2025-03-16T08:08:55.778Z","avatar_url":"https://github.com/emansarahafi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Conditional Operator Inverter\n\nThis script inverts the conditional operators in a given Python code snippet. It uses the `ast` module to parse the code and a custom `NodeTransformer` class to invert the operators.\n\n## Prerequisites\n\nBefore running the code, please make sure to install the required `astor` package by running the following command:\n\n```sh\npip install astor\n```\n\n## Usage\n\nThe script takes a Python code snippet as input and inverts the conditional operators in the code. It includes automated tests to verify the correctness of the inversion.\n\n### Example\n\nHere is an example usage of the script:\n\n```python\nexample_code = \"\"\"x = 10\ny = 5\n\nwhile x \u003c= 0 and x \u003c 0:\n    x = x + 5\n    print(\"x increased by 5\")\n\nif x \u003e= y and x != 0:\n    print(\"x is greater than y and x is not zero\")\nelse:\n    print(\"x is less than y or x is zero\")\n\"\"\"\n\n# Process the code\noperator_positions, inverted_code = invert_conditionals_and_output(example_code)\n\n# Print the results\nprint(\"\\nOperator positions:\", operator_positions)\nprint(\"\\nInverted code:\\n\")\nprint(inverted_code)\n```\n\n### Output\n\nThe script will output the positions of the inverted operators and the transformed code with the inverted operators.\n\n## Automated Tests\n\nThe script includes automated tests to verify the correctness of the inversion. The tests can be run by calling the run_tests function.\n\n### Example Tests\n\n```python\ndef test_inversion():\n    test_code = \"\"\"if x \u003c y:\n    pass\nif x != y:\n    pass\"\"\"\n    expected_operators = [((1, 3), 'Lt'), ((3, 3), 'NotEq')]\n    expected_code = \"\"\"if x \u003e= y:\n    pass\nif x == y:\n    pass\"\"\"\n\n    positions, inverted = invert_conditionals_and_output(test_code)\n    assert positions == expected_operators, f\"Expected {expected_operators}, got {positions}\"\n    assert inverted.strip() == expected_code.strip(), f\"Expected:\\n{expected_code}\\nGot:\\n{inverted}\"\n    print(\"All tests passed!\")\n\ndef test_nested_conditions():\n    test_code = \"\"\"if x \u003c y and y != z:\n    pass\"\"\"\n    expected_operators = [((1, 3), 'Lt'), ((1, 13), 'NotEq')]  # Updated column position\n    expected_code = \"\"\"if x \u003e= y and y == z:\n    pass\"\"\"\n\n    positions, inverted = invert_conditionals_and_output(test_code)\n    assert positions == expected_operators, f\"Expected {expected_operators}, got {positions}\"\n    assert inverted.strip() == expected_code.strip(), f\"Expected:\\n{expected_code}\\nGot:\\n{inverted}\"\n    print(\"Nested conditions test passed!\")\n\ndef test_no_conditions():\n    test_code = \"\"\"x = 5\ny = 10\nprint(x + y)\"\"\"\n    expected_operators = []\n    expected_code = \"\"\"x = 5\ny = 10\nprint(x + y)\"\"\"\n\n    positions, inverted = invert_conditionals_and_output(test_code)\n    assert positions == expected_operators, f\"Expected no operators, got {positions}\"\n    assert inverted.strip() == expected_code.strip(), f\"Expected:\\n{expected_code}\\nGot:\\n{inverted}\"\n    print(\"No conditions test passed!\")\n\n# Run tests\ndef run_tests():\n    test_inversion()\n    test_nested_conditions()\n    test_no_conditions()\n\nrun_tests()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femansarahafi%2Fconditional-operator-inverter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femansarahafi%2Fconditional-operator-inverter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femansarahafi%2Fconditional-operator-inverter/lists"}