Skip to content

Commit

Permalink
Use relative imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lysnikolaou committed Feb 4, 2025
1 parent 1b9908d commit 61f7061
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ backend-path = ["packaging"]
build-backend = "_pyyaml_pep517"

[tool.pytest.ini_options]
pythonpath = ["tests"]
pythonpath = ["."]
Empty file added tests/__init__.py
Empty file.
5 changes: 4 additions & 1 deletion tests/canonical.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

import yaml, yaml.composer, yaml.constructor, yaml.resolver
import yaml
import yaml.composer
import yaml.constructor
import yaml.resolver

class CanonicalError(yaml.YAMLError):
pass
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pathlib
import pytest

import setup_modules
import utils
from . import setup_modules
from . import utils


def pytest_configure(config):
Expand Down
32 changes: 16 additions & 16 deletions tests/data/construct-python-object.data
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
- !!python/object:constructor_helpers.AnObject { foo: 1, bar: two, baz: [3,3,3] }
- !!python/object:constructor_helpers.AnInstance { foo: 1, bar: two, baz: [3,3,3] }
- !!python/object:tests.constructor_helpers.AnObject { foo: 1, bar: two, baz: [3,3,3] }
- !!python/object:tests.constructor_helpers.AnInstance { foo: 1, bar: two, baz: [3,3,3] }

- !!python/object/new:constructor_helpers.AnObject { args: [1, two], kwds: {baz: [3,3,3]} }
- !!python/object/apply:constructor_helpers.AnInstance { args: [1, two], kwds: {baz: [3,3,3]} }
- !!python/object/new:tests.constructor_helpers.AnObject { args: [1, two], kwds: {baz: [3,3,3]} }
- !!python/object/apply:tests.constructor_helpers.AnInstance { args: [1, two], kwds: {baz: [3,3,3]} }

- !!python/object:constructor_helpers.AState { _foo: 1, _bar: two, _baz: [3,3,3] }
- !!python/object/new:constructor_helpers.ACustomState { state: !!python/tuple [1, two, [3,3,3]] }
- !!python/object:tests.constructor_helpers.AState { _foo: 1, _bar: two, _baz: [3,3,3] }
- !!python/object/new:tests.constructor_helpers.ACustomState { state: !!python/tuple [1, two, [3,3,3]] }

- !!python/object/new:constructor_helpers.InitArgs [1, two, [3,3,3]]
- !!python/object/new:constructor_helpers.InitArgsWithState { args: [1, two], state: [3,3,3] }
- !!python/object/new:tests.constructor_helpers.InitArgs [1, two, [3,3,3]]
- !!python/object/new:tests.constructor_helpers.InitArgsWithState { args: [1, two], state: [3,3,3] }

- !!python/object/new:constructor_helpers.NewArgs [1, two, [3,3,3]]
- !!python/object/new:constructor_helpers.NewArgsWithState { args: [1, two], state: [3,3,3] }
- !!python/object/new:tests.constructor_helpers.NewArgs [1, two, [3,3,3]]
- !!python/object/new:tests.constructor_helpers.NewArgsWithState { args: [1, two], state: [3,3,3] }

- !!python/object/apply:constructor_helpers.Reduce [1, two, [3,3,3]]
- !!python/object/apply:constructor_helpers.ReduceWithState { args: [1, two], state: [3,3,3] }
- !!python/object/apply:tests.constructor_helpers.Reduce [1, two, [3,3,3]]
- !!python/object/apply:tests.constructor_helpers.ReduceWithState { args: [1, two], state: [3,3,3] }

- !!python/object/new:constructor_helpers.Slots { state: !!python/tuple [null, { foo: 1, bar: 'two', baz: [3,3,3] } ] }
- !!python/object/new:tests.constructor_helpers.Slots { state: !!python/tuple [null, { foo: 1, bar: 'two', baz: [3,3,3] } ] }

- !!python/object/new:constructor_helpers.MyInt [3]
- !!python/object/new:constructor_helpers.MyList { listitems: [~, ~, ~] }
- !!python/object/new:constructor_helpers.MyDict { dictitems: {0, 1, 2} }
- !!python/object/new:tests.constructor_helpers.MyInt [3]
- !!python/object/new:tests.constructor_helpers.MyList { listitems: [~, ~, ~] }
- !!python/object/new:tests.constructor_helpers.MyDict { dictitems: {0, 1, 2} }
6 changes: 3 additions & 3 deletions tests/setup_modules.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import yaml

from constructor_helpers import make_constructor_helpers
from resolver_helpers import make_resolver_helpers
from structure_helpers import make_structure_helpers
from .constructor_helpers import make_constructor_helpers
from .resolver_helpers import make_resolver_helpers
from .structure_helpers import make_structure_helpers


RUNNING_C_EXT = False
Expand Down
2 changes: 1 addition & 1 deletion tests/structure_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yaml
import canonical # Needed for CanonicalLoader
from . import canonical # Needed for CanonicalLoader


def make_structure_helpers():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_canonical.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

import yaml
import canonical
from utils import filter_data_files
from . import canonical
from .utils import filter_data_files


@pytest.mark.parametrize("canonical_filename", filter_data_files(".canonical"))
Expand Down
6 changes: 3 additions & 3 deletions tests/test_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import yaml
import yaml.tokens
from utils import filter_data_files, load_code, serialize_value
from .utils import filter_data_files, load_code, serialize_value


@pytest.mark.needs_constructor_helpers
Expand All @@ -11,7 +11,7 @@ def test_constructor_types(data_filename, code_filename):
import datetime
import signal

from constructor_helpers import (
from .constructor_helpers import (
MyLoader, MyTestClass1, FixedOffset, MyTestClass2, MyTestClass3, YAMLObject1, AnObject,
AnInstance, AState, ACustomState, InitArgs, InitArgsWithState, NewArgs, NewArgsWithState,
Reduce, ReduceWithState, Slots, MyInt, MyList, MyDict,
Expand All @@ -36,7 +36,7 @@ def test_constructor_types(data_filename, code_filename):
@pytest.mark.needs_constructor_helpers
@pytest.mark.parametrize("data_filename", filter_data_files(".subclass_blacklist"))
def test_subclass_blacklist_types(data_filename):
from constructor_helpers import MyFullLoader
from .constructor_helpers import MyFullLoader

with pytest.raises(yaml.YAMLError):
with open(data_filename, 'rb') as file:
Expand Down
1 change: 1 addition & 0 deletions tests/test_dump_load.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

import yaml


Expand Down
2 changes: 1 addition & 1 deletion tests/test_emitter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files

def _compare_events(events1, events2):
assert len(events1) == len(events2), (events1, events2)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

import yaml
import test_emitter
from utils import filter_data_files
from . import test_emitter
from .utils import filter_data_files

@pytest.mark.parametrize("error_filename", filter_data_files(".loader-error"))
def test_loader_error(error_filename):
Expand Down
8 changes: 6 additions & 2 deletions tests/test_input_output.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import codecs, io, tempfile, os, os.path
import codecs
import io
import tempfile
import os
import os.path

import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files


@pytest.mark.parametrize("unicode_filename", filter_data_files(".unicode"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mark.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files


@pytest.mark.parametrize("marks_filename", filter_data_files(".marks"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multi_constructor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import yaml
from utils import filter_data_files, load_code
from .utils import filter_data_files, load_code


def myconstructor1(constructor, tag, node):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import yaml.reader
from utils import filter_data_files
from .utils import filter_data_files

def _run_reader(data):
with pytest.raises(yaml.reader.ReaderError):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_recursive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files

class AnInstance:

Expand Down
4 changes: 2 additions & 2 deletions tests/test_representer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from utils import filter_data_files, load_code, serialize_value
from .utils import filter_data_files, load_code, serialize_value


@pytest.mark.needs_constructor_helpers
Expand All @@ -10,7 +10,7 @@ def test_representer_types(code_filename):
import datetime
import signal

from constructor_helpers import (
from .constructor_helpers import (
MyDumper, MyLoader, FixedOffset, AnObject, AnInstance, AState, today, MyTestClass1,
ACustomState, MyTestClass2, InitArgs, MyTestClass3, InitArgsWithState, YAMLObject1,
NewArgs, NewArgsWithState, Reduce, ReduceWithState, Slots, MyInt, MyList, MyDict
Expand Down
6 changes: 3 additions & 3 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files


@pytest.mark.parametrize("data_filename,detect_filename", filter_data_files(".data", ".detect"))
Expand Down Expand Up @@ -38,7 +38,7 @@ def _convert_node(node):
@pytest.mark.needs_resolver_helpers
@pytest.mark.parametrize("data_filename,path_filename", filter_data_files(".data", ".path"))
def test_path_resolver_loader(data_filename, path_filename):
from resolver_helpers import MyLoader
from .resolver_helpers import MyLoader

with open(data_filename, 'rb') as file:
nodes1 = list(yaml.compose_all(file.read(), Loader=MyLoader))
Expand All @@ -53,7 +53,7 @@ def test_path_resolver_loader(data_filename, path_filename):
@pytest.mark.needs_resolver_helpers
@pytest.mark.parametrize("data_filename,path_filename", filter_data_files(".data", ".path"))
def test_path_resolver_dumper(data_filename, path_filename):
from resolver_helpers import MyDumper
from .resolver_helpers import MyDumper

for filename in [data_filename, path_filename]:
with open(filename, 'rb') as file:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files


def check_bool(value, expected):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sort_keys.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files

@pytest.mark.parametrize("input_filename,sorted_filename", filter_data_files(".sort", ".sorted"))
def test_sort_keys(input_filename, sorted_filename):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_structure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files


def _convert_structure(loader):
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_composer(data_filename, canonical_filename):
@pytest.mark.needs_structure_helpers
@pytest.mark.parametrize("data_filename,canonical_filename", filter_data_files('.data', '.canonical'))
def test_constructor(data_filename, canonical_filename):
from structure_helpers import MyLoader, MyCanonicalLoader
from .structure_helpers import MyLoader, MyCanonicalLoader

native1 = None
native2 = None
Expand Down
4 changes: 1 addition & 3 deletions tests/test_tokens.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pprint

import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files

# Tokens mnemonic:
# directive: %
Expand Down
2 changes: 1 addition & 1 deletion tests/test_yaml_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

import yaml
from utils import filter_data_files
from .utils import filter_data_files


@pytest.mark.c_only
Expand Down

0 comments on commit 61f7061

Please sign in to comment.