[-] s12@sopuli.xyz 30 points 2 months ago* (last edited 2 months ago)

… since when did the project have customers lol?

11
submitted 5 months ago by s12@sopuli.xyz to c/python@programming.dev

I have a repository that contains multiple programs:

.
└── Programs
    ├── program1
    │   └── Generic_named.py
    └── program2
        └── Generic_named.py

I would like to add testing to this repository.

I have attempted to do it like this:

.
├── Programs
│   ├── program1
│   │   └── Generic_named.py
│   └── program2
│       └── Generic_named.py
└── Tests
    ├── mock
    │   ├── 1
    │   │   └── custom_module.py
    │   └── 2
    │       └── custom_module.py
    ├── temp
    ├── test1.py
    └── test2.py

Where temp is a folder to store each program temporarily with mock versions of any required imports that can not be stored directly with the program.

Suppose we use a hello world example like this:

cat Programs/program1/Generic_named.py
import custom_module

def main():
    return custom_module.out()


cat Programs/program2/Generic_named.py
import custom_module

def main():
    return custom_module.out("Goodbye, World!")


cat Tests/mock/1/custom_module.py
def out():return "Hello, World!"


cat Tests/mock/2/custom_module.py
def out(x):return x

And I were to use these scripts to test it:

cat Tests/test1.py
import unittest
import os
import sys
import shutil

if os.path.exists('Tests/temp/1'):
    shutil.rmtree('Tests/temp/1')

shutil.copytree('Tests/mock/1', 'Tests/temp/1/')
shutil.copyfile('Programs/program1/Generic_named.py', 'Tests/temp/1/Generic_named.py')

sys.path.append('Tests/temp/1')
import Generic_named
sys.path.remove('Tests/temp/1')

class Test(unittest.TestCase):
    def test_case1(self):
            self.assertEqual(Generic_named.main(), "Hello, World!")

if __name__ == '__main__':
    unittest.main()



cat Tests/test2.py
import unittest
import os
import sys
import shutil

if os.path.exists('Tests/temp/2'):
    shutil.rmtree('Tests/temp/2')

shutil.copytree('Tests/mock/2', 'Tests/temp/2')
shutil.copyfile('Programs/program2/Generic_named.py', 'Tests/temp/2/Generic_named.py')

sys.path.append('Tests/temp/2')
import Generic_named
sys.path.remove('Tests/temp/2')

class Test(unittest.TestCase):
    def test_case1(self):
            self.assertEqual(Generic_named.main(), "Goodbye, World!")

if __name__ == '__main__':
    unittest.main()

Both tests pass when run individually:

python3 -m unittest Tests/test1.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK


python3 -m unittest Tests/test2.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

However, they fail when being run together:

python3 -m unittest discover -p test*.py -s Tests/
.F
======================================================================
FAIL: test_case1 (test2.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/s/Documents/Coding practice/2024/Test Mess/1/Tests/test2.py", line 18, in test_case1
    self.assertEqual(Generic_named.main(), "Goodbye, World!")
AssertionError: 'Hello, World!' != 'Goodbye, World!'
- Hello, World!
+ Goodbye, World!


----------------------------------------------------------------------
Ran 2 tests in 0.001s

FAILED (failures=1)

If I try to use a different temporary name for one of the scripts I am trying to test,

cat Tests/test2.py
import unittest
import os
import sys
import shutil

if os.path.exists('Tests/temp/2'):
    shutil.rmtree('Tests/temp/2')

shutil.copytree('Tests/mock/2', 'Tests/temp/2')
shutil.copyfile('Programs/program2/Generic_named.py', 'Tests/temp/2/Generic_named1.py')

sys.path.append('Tests/temp/2')
import Generic_named1
sys.path.remove('Tests/temp/2')

class Test(unittest.TestCase):
    def test_case1(self):
            self.assertEqual(Generic_named1.main(), "Goodbye, World!")

if __name__ == '__main__':
    unittest.main()

Then I get a different error:

python3 -m unittest discover -p test*.py -s Tests/
.E
======================================================================
ERROR: test_case1 (test2.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/s/Documents/Coding practice/2024/Test Mess/2/Tests/test2.py", line 18, in test_case1
    self.assertEqual(Generic_named1.main(), "Goodbye, World!")
  File "/home/s/Documents/Coding practice/2024/Test Mess/2/Tests/temp/2/Generic_named1.py", line 4, in main
    return custom_module.out("Goodbye, World!")
TypeError: out() takes 0 positional arguments but 1 was given

----------------------------------------------------------------------
Ran 2 tests in 0.001s

FAILED (errors=1)

It seems to be trying to import the same file, despite me using a different file from a different path with the same name. This seems strange, as I've been making sure to undo any changes to the Python Path after importing what I wish to test. Is there any way to mock the path? I can't change the name of the custom_module, as that would require changing the programs I wish to test.

How should I write, approach, or setup these tests such that they can be tested with unittest discover the same as they can individually?

[-] s12@sopuli.xyz 37 points 6 months ago

PLEASE COMEFROM 🏷

[-] s12@sopuli.xyz 36 points 6 months ago

Umm… someone explain this code please?

[-] s12@sopuli.xyz 25 points 7 months ago

Me: “Is bugger a term that denotes a bugged state?
Senior: “No. That’s just what I have it print to show if something has failed.”

4
submitted 7 months ago by s12@sopuli.xyz to c/animemes@ani.social
[-] s12@sopuli.xyz 54 points 7 months ago

Translation layers are vital for preservation.

The malicious people in NVIDIA who are pushing for this are being very evil right now.

2
submitted 8 months ago* (last edited 7 months ago) by s12@sopuli.xyz to c/unitedkingdom@feddit.uk

The recent stopkillinggames campaign has been my first exposure to UK petitions.

Link to petition: https://petition.parliament.uk/petitions/659071
Link to campaign: stopkillinggames.com
Link to the campaigner’s video

Update: Link to the campaigner’s video on the response

[-] s12@sopuli.xyz 27 points 8 months ago

The IT people! The DEV team’s worst nemesis! They must be stopped before we are destroyed!

[-] s12@sopuli.xyz 29 points 9 months ago* (last edited 9 months ago)

Have you heard of GIMP?

If that isn’t what you need; this site may help you: https://alternativeto.net/software/adobe-photoshop/

[-] s12@sopuli.xyz 32 points 9 months ago

The recent regulation changes at the end of February kinda killed GRUMBOSS though.

https://youtube.com/shorts/xEHSbHH4F_k?si=06iPTcwXRgQuT2qb

[-] s12@sopuli.xyz 49 points 9 months ago* (last edited 9 months ago)

Got a Windows app you want to run on Linux? Wine and Proton are well known translation layers.

I guess Graphics Cards are similar. CUDA is basically the NVIDIA equivalent of .exe I think.

[-] s12@sopuli.xyz 23 points 10 months ago

WHAT THE F-

Oh! I forgot to hit ctrl-s…

2
submitted 10 months ago by s12@sopuli.xyz to c/steamdeck@sopuli.xyz

When I try to turn off Use CPU in settings, it says "No compatible graphics card found!".

During the instillation, I got an error "hipErrorNoBinaryForGpu" which I looked up and found the command export HSA_OVERRIDE_GFX_VERSION=10.3.0 which got me through the instillation.

I don't know much about GPUs, so thanks in advance for any help/advice!

[-] s12@sopuli.xyz 91 points 1 year ago

Thought that seemed really cute. Nice way to try to break through social anxiety.

Then I saw that it started as a wrong number message. Then I realised…

Damn scam bots!

8
submitted 1 year ago* (last edited 1 year ago) by s12@sopuli.xyz to c/godot@programming.dev

I want to create a "gradual colour change" effect in Godot.

eg: some_set_font_color_func(Color8(255,n,n) where n gradually decreases to make the text fade from white to red.

I can't figure out what function I would use in place of some_set_font_color_func to change a font's colour.

Godot themes are somewhat confusing. Given some var var UI:control how would I set the colour of any font(s) contained within that node?

[-] s12@sopuli.xyz 23 points 1 year ago

I’ve been playing Deep Rock Galactic with my friend. It’s been really fun.

Works great on deck apart from small text sometimes being a problem.

1
submitted 1 year ago by s12@sopuli.xyz to c/linuxanimemes@ani.social

cross-posted from: https://sopuli.xyz/post/770433

Any tips for creating memes using FOSS. I made this in Impress, then copy-pasted it into gimp, and it reduced the quality a lot.

In PowerPoint, you can just select everything, then right-click -> save as image, and it saves whatever you have selected rather than the whole slide. There doesn't seem to be a way to do that in Impress, but I realised you could copy-paste into Gimp and that would copy the objects as an image, so I've been making memes that way.

25
submitted 1 year ago* (last edited 1 year ago) by s12@sopuli.xyz to c/godot@programming.dev

I’m just curious about which is the most efficient way of doing this kind of node enumiration:

for i in something():
    o=[var1,var2,var3,varN][i]
    o.new()
    o.do_something_based_on_number_of_loops()
    add_child(o)

or

for i in something():
    match i:
        0:
            o=var1
            o.new()
            o.do_something_based_on_number_of_loops()
            add_child(o)
        1:
            o=var2
            o.new()
            o.do_something_based_on_number_of_loops()
            add_child(o)
        2:
            o=var3
            o.new()
            o.do_something_based_on_number_of_loops()
            add_child(o)
        N-1:
            o=varN
            o.new()
            o.do_something_based_on_number_of_loops()
            add_child(o)

or

var items = [var1,var2,var3,varN]
for i in something():
    o=items[i]
    o.new()
    o.do_something_based_on_number_of_loops()
    add_child(o)

Or is there a more efficient way of doing it?

Edit: Sorry if that wasn't clear. Is it better to constantly get something from an "unstored list", store the list in a variable, or not use a list and use a match statement instead? Do they have any advantages/disadvantages that make them better in certain situations?

73
submitted 1 year ago* (last edited 1 year ago) by s12@sopuli.xyz to c/memes@sopuli.xyz

Ah. It's still called cake day over here.
Wasn’t sure if it had to be called something different on Lemmy.

view more: next ›

s12

joined 2 years ago