litio


Namelitio JSON
Version 1.6.1 PyPI version JSON
download
home_pagehttps://github.com/lizardwine/litio
SummaryA simple tool for testing
upload_time2024-04-08 22:28:31
maintainerNone
docs_urlNone
authorLizardwine
requires_python>=3.6
licenseGPL v3.0
keywords testing tester
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            A simple tool for testing

# litio

## how to use

## example 1: The basics

### install
```bash
pip install litio
```
### run
```bash
litio run
```

### litio.yml
```yaml
name: My Awesome Title

tests:
  firsth-test: # test name
    path: ./tests/test1.py # path to python file
    functions: # functions list
      - pow: # function name
          inputs: # inputs
            # arguments with name of parameters
            base: 2
            exponent: 2
          expected:
            value: 4 # expected value
            comparator: Equals
```

### test1.py:
```python
def pow(base, exponent):
    return base**exponent
```

## example 2: If something fails?

### test2.py:
```python
def pow(base, exponent):
    return base / exponent # it's obviously not working.
```



litio.yml:
```yaml
name: My Awesome Title
api-key: YOUR_OPENAI_API_KEY_ENVIRONMENT_VARIABLE # the name of the environment variable, NOT THE API KEY!
tests:
  failed-test:
    path: ./tests/test2.py
    functions: 
      - pow:
          inputs:
            base: 2
            exponent: 2
          expected:
            value: 4
            comparator: Equals
          verbose: true 
          auto-fix: true # auto fix function using AI if call fails
```

## how auto-fix works?
The "auto-fix" parameter instructs litio to use artificial intelligence to automatically repair and replace the function in the source code. If you prefer to confirm before consulting AI, you can use the "use-ai" parameter instead of "auto-fix."

## example 3: if a tests is not ready yet?

### test3.py:
```python
def coming_soon():
    pass # it's not ready yet
```

litio.yml:
```yaml
name: My Awesome Title
tests:
  not-ready-test:
    path: ./tests/test3.py
    functions: 
      - coming_soon:
          expected:
            value: i am not ready yet
            comparator: Equals
          ignore: true # ignore this test and continue
```

# Litio commands

- ## `run`
  - Action: Runs the tests.
  - parameters:
    - `--verbose`(aliases: `-V`): Prints the full function call.
    - `--output`(aliases: `-o`): The style of the output. It can be `capybara` or `classic` or you can install a custom style.
    - `--ai`/`--no-ai`: enable/disable auto-fix using AI.
- ## `install`
  - Action: Installs a Litio package.
  - parameters:
    - `module`: The name of the module to install, must be in format `author/module` or `author/module@version`.
    - `--upgrade`(aliases: `-u`): install the latest version of the module.
 - ## `uninstall`
  - Action: Uninstalls a Litio package.
  - parameters:
    - `module`: The name of the module to uninstall, must be in format `author/module`.
# Litio config file reference

### The config file must be in YAML format and named `litio.yml`

## `name` paramater

- The `name` parameter is the title of the config file.

## `api-key` parameter

- The `api-key` parameter is the name of the environment variable that contains the OpenAI API key, NOT THE API KEY!

## `output-style` parameter
- The `output-style` parameter is the style of the output. It can be `capybara` or `classic` for now.

## `tests` parameter

- The `tests` parameter is a dictionary of tests.

## Tests structure

- The test name is the name of the test.
- The `path` parameter is the path to the Python file that contains the functions, methods or classmethods to test.
- The `functions` parameter is a list of functions to test.

Looks like this:
```yaml
...
tests:
  first-test:
    path: ./src/utils.py
    functions:
      - add: # function name
          ...


```

## Function structure

- The function name is the name of the function.
- The `inputs` parameter is a dictionary of inputs.
- The `expected` parameter is a dictionary with expected value and comparator.
- The `verbose` parameter is a boolean that indicates whether to print the full function call.
- The `auto-fix` parameter is a boolean that indicates whether to use AI to automatically fix the function. Only can be used with the `Equals` comparator.
- The `use-ai` parameter is a boolean that indicates whether to use AI to fix the function. Only can be used with the `Equals` comparator.
- The `ignore` parameter is a boolean that indicates whether to ignore the function.

Looks like this:
```yaml
...
tests:
  first-test:
    path: ./src/utils.py
    functions:
      - FUNCTION_NAME: # (e.g. subtract)
          inputs:
            a: 1 # arguments with name of parameters
            b: 2 # must be the same as the name of the parameter
          expected:
            value: -1 # expected value
            comparator: Equals

```

## Using methods

The syntax for a method is the same as that of a function, except that you need to add the "instance" parameter with the values to instantiate an object of that class.

Looks like this:
```yaml
...
tests:
  first-test:
    path: ./src/utils.py
    functions:
      - Person.get_age:
          instance:
            name: John
            age: 30
          expected:
            value: 30
            comparator: Equals

```

## The expected parameter

- The `comparator` parameter is the way to compare the expected value.
- The `value` parameter is the expected value.
+ you can access the attributes of the returned object using the dot notation. Look like this:
```yaml
...
- add_lists:
    inputs:
      a: [1, 2]
      b: [3, 4]
    expected:
      # the value returned is [1, 2, 3, 4]
      value.0: 1 # access to value[0]
      comparator: Equals
```
you also can use ranges:
```yaml
...
- add_lists:
    inputs:
      a: [1, 2]
      b: [3, 4]
    expected:
      # the value returned is [1, 2, 3, 4]
      value.1;3: 1 # access to the range value[1:3]
      # NOTE: use semicolon(;) to indicate the range(e.g. value.1;3), not the colon(:) because conflict with the yaml syntax
      comparator: Equals
```
you can also use spacing in the range:
```yaml
...
- add_lists:
    inputs:
      a: [1, 2]
      b: [3, 4]
    expected:
      value.;;2: [1, 3] # access to value[::2]
      comparator: Equals
```
you also can access to a key in the dictionary:
```yaml
...
- add_dicts:
    inputs:
      a: {"a": 1, "b": 2}
      b: {"c": 3, "d": 4}
    expected:
      value.a: 1
      comparator: Equals
```
you also can use dot notation multiple times:
```yaml
...
- add_dicts:
    inputs:
      a: {"a": {"b": 1}}
      b: {"c": {"d": 2}}
    expected:
      value.a.b: 1 # access to value["a"]["b"]
      comparator: Equals
```
if function returns an object, you can access to the attributes of that object using the dot notation:
```yaml
...
- create_person_object:
    inputs:
      name: John
      age: 30
    expected:
      value.name: John # access to value.name
      comparator: Equals
```


## What comparators are there?

- `Equals`
- `Greater`
- `Less`
- `GreaterOrEqual`
- `LessOrEqual`
- `NotEquals`
- `Is`
- `IsNot`
- `IsNone`
- `IsNotNone`
- `IsInstance`
- `IsNotInstance`

# How can i create a module?

### Every module must have a `litio.py` file in root directory.

### Example module for output styles:

#### litio.py
```python
import ... # your dependecies here

def my_own_output_style(args):
    ... # your code here

litio = {
  'output': {
    'my-own-output-style-name': my_own_output_style
  }
}
```

### When your module is ready to use, you can publish it to github and install it using `litio install you/your-module-name` example: `litio install lizardwine/litio-package`

## litio dictionary reference
### you can repleace any litio function
- output: you can add and replace any output style
  - `classic`: classic output
  - `capybara`: capybara output
- options: you can add and replace any option for litio command
  - `--version`: shows the litio version and exit

- sub_commands: you can add and replace any sub command
  - `run`: run the tests in litio.yml
  - `install`: install a module
  - `uninstall`: uninstall a module
- utils: you can add and replace any utility
  - `extract_function_code`: extract the code of a function from a file
  - `Args`: set self attributes from a dictionary
  - `OutputArgs`: an organizer for the output arguments
  - `params_to_dict`: convert a list of parameters to a dictionary
  - `eval_param_values`: evaluate the values of a list of parameters
  - `Kwargs`: set self attributes from a keyword arguments

- tester: you can replace the tester function
  - `test`: test a function with the given inputs and expected values

- ai: you can add or replace any AI powered function
  - `BugFixer`: class for bug fixing
  - `fix_bug`: fix a bug in a function with BugFixer



#### If you module has dependencies, you must add them in `requirements.txt` file in root directory.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lizardwine/litio",
    "name": "litio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "testing, tester",
    "author": "Lizardwine",
    "author_email": "lizardwine@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ae/ae/000ac19ba371f485fd8a65226c858b381329d14fb7284bf0774bc8aa7cab/litio-1.6.1.tar.gz",
    "platform": null,
    "description": "A simple tool for testing\n\n# litio\n\n## how to use\n\n## example 1: The basics\n\n### install\n```bash\npip install litio\n```\n### run\n```bash\nlitio run\n```\n\n### litio.yml\n```yaml\nname: My Awesome Title\n\ntests:\n  firsth-test: # test name\n    path: ./tests/test1.py # path to python file\n    functions: # functions list\n      - pow: # function name\n          inputs: # inputs\n            # arguments with name of parameters\n            base: 2\n            exponent: 2\n          expected:\n            value: 4 # expected value\n            comparator: Equals\n```\n\n### test1.py:\n```python\ndef pow(base, exponent):\n    return base**exponent\n```\n\n## example 2: If something fails?\n\n### test2.py:\n```python\ndef pow(base, exponent):\n    return base / exponent # it's obviously not working.\n```\n\n\n\nlitio.yml:\n```yaml\nname: My Awesome Title\napi-key: YOUR_OPENAI_API_KEY_ENVIRONMENT_VARIABLE # the name of the environment variable, NOT THE API KEY!\ntests:\n  failed-test:\n    path: ./tests/test2.py\n    functions: \n      - pow:\n          inputs:\n            base: 2\n            exponent: 2\n          expected:\n            value: 4\n            comparator: Equals\n          verbose: true \n          auto-fix: true # auto fix function using AI if call fails\n```\n\n## how auto-fix works?\nThe \"auto-fix\" parameter instructs litio to use artificial intelligence to automatically repair and replace the function in the source code. If you prefer to confirm before consulting AI, you can use the \"use-ai\" parameter instead of \"auto-fix.\"\n\n## example 3: if a tests is not ready yet?\n\n### test3.py:\n```python\ndef coming_soon():\n    pass # it's not ready yet\n```\n\nlitio.yml:\n```yaml\nname: My Awesome Title\ntests:\n  not-ready-test:\n    path: ./tests/test3.py\n    functions: \n      - coming_soon:\n          expected:\n            value: i am not ready yet\n            comparator: Equals\n          ignore: true # ignore this test and continue\n```\n\n# Litio commands\n\n- ## `run`\n  - Action: Runs the tests.\n  - parameters:\n    - `--verbose`(aliases: `-V`): Prints the full function call.\n    - `--output`(aliases: `-o`): The style of the output. It can be `capybara` or `classic` or you can install a custom style.\n    - `--ai`/`--no-ai`: enable/disable auto-fix using AI.\n- ## `install`\n  - Action: Installs a Litio package.\n  - parameters:\n    - `module`: The name of the module to install, must be in format `author/module` or `author/module@version`.\n    - `--upgrade`(aliases: `-u`): install the latest version of the module.\n - ## `uninstall`\n  - Action: Uninstalls a Litio package.\n  - parameters:\n    - `module`: The name of the module to uninstall, must be in format `author/module`.\n# Litio config file reference\n\n### The config file must be in YAML format and named `litio.yml`\n\n## `name` paramater\n\n- The `name` parameter is the title of the config file.\n\n## `api-key` parameter\n\n- The `api-key` parameter is the name of the environment variable that contains the OpenAI API key, NOT THE API KEY!\n\n## `output-style` parameter\n- The `output-style` parameter is the style of the output. It can be `capybara` or `classic` for now.\n\n## `tests` parameter\n\n- The `tests` parameter is a dictionary of tests.\n\n## Tests structure\n\n- The test name is the name of the test.\n- The `path` parameter is the path to the Python file that contains the functions, methods or classmethods to test.\n- The `functions` parameter is a list of functions to test.\n\nLooks like this:\n```yaml\n...\ntests:\n  first-test:\n    path: ./src/utils.py\n    functions:\n      - add: # function name\n          ...\n\n\n```\n\n## Function structure\n\n- The function name is the name of the function.\n- The `inputs` parameter is a dictionary of inputs.\n- The `expected` parameter is a dictionary with expected value and comparator.\n- The `verbose` parameter is a boolean that indicates whether to print the full function call.\n- The `auto-fix` parameter is a boolean that indicates whether to use AI to automatically fix the function. Only can be used with the `Equals` comparator.\n- The `use-ai` parameter is a boolean that indicates whether to use AI to fix the function. Only can be used with the `Equals` comparator.\n- The `ignore` parameter is a boolean that indicates whether to ignore the function.\n\nLooks like this:\n```yaml\n...\ntests:\n  first-test:\n    path: ./src/utils.py\n    functions:\n      - FUNCTION_NAME: # (e.g. subtract)\n          inputs:\n            a: 1 # arguments with name of parameters\n            b: 2 # must be the same as the name of the parameter\n          expected:\n            value: -1 # expected value\n            comparator: Equals\n\n```\n\n## Using methods\n\nThe syntax for a method is the same as that of a function, except that you need to add the \"instance\" parameter with the values to instantiate an object of that class.\n\nLooks like this:\n```yaml\n...\ntests:\n  first-test:\n    path: ./src/utils.py\n    functions:\n      - Person.get_age:\n          instance:\n            name: John\n            age: 30\n          expected:\n            value: 30\n            comparator: Equals\n\n```\n\n## The expected parameter\n\n- The `comparator` parameter is the way to compare the expected value.\n- The `value` parameter is the expected value.\n+ you can access the attributes of the returned object using the dot notation. Look like this:\n```yaml\n...\n- add_lists:\n    inputs:\n      a: [1, 2]\n      b: [3, 4]\n    expected:\n      # the value returned is [1, 2, 3, 4]\n      value.0: 1 # access to value[0]\n      comparator: Equals\n```\nyou also can use ranges:\n```yaml\n...\n- add_lists:\n    inputs:\n      a: [1, 2]\n      b: [3, 4]\n    expected:\n      # the value returned is [1, 2, 3, 4]\n      value.1;3: 1 # access to the range value[1:3]\n      # NOTE: use semicolon(;) to indicate the range(e.g. value.1;3), not the colon(:) because conflict with the yaml syntax\n      comparator: Equals\n```\nyou can also use spacing in the range:\n```yaml\n...\n- add_lists:\n    inputs:\n      a: [1, 2]\n      b: [3, 4]\n    expected:\n      value.;;2: [1, 3] # access to value[::2]\n      comparator: Equals\n```\nyou also can access to a key in the dictionary:\n```yaml\n...\n- add_dicts:\n    inputs:\n      a: {\"a\": 1, \"b\": 2}\n      b: {\"c\": 3, \"d\": 4}\n    expected:\n      value.a: 1\n      comparator: Equals\n```\nyou also can use dot notation multiple times:\n```yaml\n...\n- add_dicts:\n    inputs:\n      a: {\"a\": {\"b\": 1}}\n      b: {\"c\": {\"d\": 2}}\n    expected:\n      value.a.b: 1 # access to value[\"a\"][\"b\"]\n      comparator: Equals\n```\nif function returns an object, you can access to the attributes of that object using the dot notation:\n```yaml\n...\n- create_person_object:\n    inputs:\n      name: John\n      age: 30\n    expected:\n      value.name: John # access to value.name\n      comparator: Equals\n```\n\n\n## What comparators are there?\n\n- `Equals`\n- `Greater`\n- `Less`\n- `GreaterOrEqual`\n- `LessOrEqual`\n- `NotEquals`\n- `Is`\n- `IsNot`\n- `IsNone`\n- `IsNotNone`\n- `IsInstance`\n- `IsNotInstance`\n\n# How can i create a module?\n\n### Every module must have a `litio.py` file in root directory.\n\n### Example module for output styles:\n\n#### litio.py\n```python\nimport ... # your dependecies here\n\ndef my_own_output_style(args):\n    ... # your code here\n\nlitio = {\n  'output': {\n    'my-own-output-style-name': my_own_output_style\n  }\n}\n```\n\n### When your module is ready to use, you can publish it to github and install it using `litio install you/your-module-name` example: `litio install lizardwine/litio-package`\n\n## litio dictionary reference\n### you can repleace any litio function\n- output: you can add and replace any output style\n  - `classic`: classic output\n  - `capybara`: capybara output\n- options: you can add and replace any option for litio command\n  - `--version`: shows the litio version and exit\n\n- sub_commands: you can add and replace any sub command\n  - `run`: run the tests in litio.yml\n  - `install`: install a module\n  - `uninstall`: uninstall a module\n- utils: you can add and replace any utility\n  - `extract_function_code`: extract the code of a function from a file\n  - `Args`: set self attributes from a dictionary\n  - `OutputArgs`: an organizer for the output arguments\n  - `params_to_dict`: convert a list of parameters to a dictionary\n  - `eval_param_values`: evaluate the values of a list of parameters\n  - `Kwargs`: set self attributes from a keyword arguments\n\n- tester: you can replace the tester function\n  - `test`: test a function with the given inputs and expected values\n\n- ai: you can add or replace any AI powered function\n  - `BugFixer`: class for bug fixing\n  - `fix_bug`: fix a bug in a function with BugFixer\n\n\n\n#### If you module has dependencies, you must add them in `requirements.txt` file in root directory.\n",
    "bugtrack_url": null,
    "license": "GPL v3.0",
    "summary": "A simple tool for testing",
    "version": "1.6.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/lizardwine/litio/issues",
        "Homepage": "https://github.com/lizardwine/litio"
    },
    "split_keywords": [
        "testing",
        " tester"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f95af0bc39f9c3b5b8bf9a660d0d668203da95a30337e9b82688b2d60ab9e4d6",
                "md5": "1c45845e1e76fc5c8f0dceb174c00760",
                "sha256": "0ab3fdd469dcfa3b41b4a4698a441527a1544d73cde9e9773223a6fd8cf8559e"
            },
            "downloads": -1,
            "filename": "litio-1.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1c45845e1e76fc5c8f0dceb174c00760",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 26784,
            "upload_time": "2024-04-08T22:28:29",
            "upload_time_iso_8601": "2024-04-08T22:28:29.740674Z",
            "url": "https://files.pythonhosted.org/packages/f9/5a/f0bc39f9c3b5b8bf9a660d0d668203da95a30337e9b82688b2d60ab9e4d6/litio-1.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aeae000ac19ba371f485fd8a65226c858b381329d14fb7284bf0774bc8aa7cab",
                "md5": "310b4c4c313e087319c926af60c90762",
                "sha256": "31cd0dbbd4b299b6d9e01c8501e7feedb0da94ee7159f4b30dde4b5b94296df9"
            },
            "downloads": -1,
            "filename": "litio-1.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "310b4c4c313e087319c926af60c90762",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 28116,
            "upload_time": "2024-04-08T22:28:31",
            "upload_time_iso_8601": "2024-04-08T22:28:31.651942Z",
            "url": "https://files.pythonhosted.org/packages/ae/ae/000ac19ba371f485fd8a65226c858b381329d14fb7284bf0774bc8aa7cab/litio-1.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-08 22:28:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lizardwine",
    "github_project": "litio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "litio"
}
        
Elapsed time: 0.22249s